|
<?php |
|
namespace Acme\Donate\Form; |
|
|
|
use TYPO3\Flow\Annotations as Flow; |
|
use TYPO3\Form\Core\Model\FormDefinition; |
|
use \TYPO3\Flow\Validation\Validator as Validator; |
|
use \Acme\Donate\Form\Finishers as DonateFinisher; |
|
use \TYPO3\Form\Finishers as TYPO3Finisher; |
|
use \TYPO3\Form\Factory as Factory; |
|
|
|
/** |
|
* Class DonateFormFactory |
|
* |
|
* @package Acme\Donate\Form |
|
*/ |
|
class DonateFormFactory extends Factory\AbstractFormFactory { |
|
|
|
/** |
|
* @param array $factorySpecificConfiguration |
|
* @param string $presetName |
|
* @return \TYPO3\Form\Core\Model\FormDefinition |
|
*/ |
|
public function build(array $factorySpecificConfiguration, $presetName) { |
|
$formConfiguration = $this->getPresetConfiguration($presetName); |
|
$form = new FormDefinition('donate', $formConfiguration); |
|
$form->setRenderingOption('submitButtonLabel', 'To payment'); |
|
$userinformationPage = $form->createPage('page1'); |
|
|
|
$sectionPrice = $userinformationPage->createElement('sectionPrice', 'TYPO3.Form:Section'); |
|
|
|
$price = $sectionPrice->createElement('price', 'TYPO3.Form:SingleSelectRadiobuttons'); |
|
$price->setProperty('required', 'required'); |
|
$price->setProperty('options', $priceOptions); |
|
$price->setProperty('optionSets', $priceOptionSets); |
|
|
|
$price->setLabel('Amount'); |
|
|
|
$sectionInfo = $userinformationPage->createElement('sectionInfo', 'TYPO3.Form:Section'); |
|
$sectionInfo->setProperty('elementClassAttribute', 'hidden'); |
|
|
|
$name = $sectionInfo->createElement('name', 'TYPO3.Form:SingleLineText'); |
|
$name->setLabel('Name'); |
|
$name->setProperty('required', 'required'); |
|
$name->addValidator(new Validator\NotEmptyValidator()); |
|
$name->addValidator(new Validator\LabelValidator()); |
|
$name->addValidator(new Validator\TextValidator()); |
|
$name->addValidator(new Validator\StringLengthValidator(array('minimum' => 5, 'maximum' => 100))); |
|
|
|
$street = $sectionInfo->createElement('street', 'TYPO3.Form:SingleLineText'); |
|
$street->setLabel('Address'); |
|
$street->setProperty('required', 'required'); |
|
$street->addValidator(new Validator\NotEmptyValidator()); |
|
$street->addValidator(new Validator\LabelValidator()); |
|
$street->addValidator(new Validator\TextValidator()); |
|
$street->addValidator(new Validator\StringLengthValidator(array('minimum' => 2, 'maximum' => 100))); |
|
|
|
$zip = $sectionInfo->createElement('zip', 'TYPO3.Form:SingleLineText'); |
|
$zip->setLabel('Zipcode'); |
|
$zip->setProperty('required', 'required'); |
|
$zip->setProperty('elementType', 'tel'); |
|
$zip->addValidator(new Validator\NotEmptyValidator()); |
|
$zip->addValidator(new Validator\LabelValidator()); |
|
$zip->addValidator(new Validator\TextValidator()); |
|
$zip->addValidator(new Validator\StringLengthValidator(array('minimum' => 1, 'maximum' => 10))); |
|
|
|
$city = $sectionInfo->createElement('city', 'TYPO3.Form:SingleLineText'); |
|
$city->setLabel('City'); |
|
$city->setProperty('required', 'required'); |
|
$city->addValidator(new Validator\NotEmptyValidator()); |
|
$city->addValidator(new Validator\LabelValidator()); |
|
$city->addValidator(new Validator\TextValidator()); |
|
$city->addValidator(new Validator\StringLengthValidator(array('minimum' => 2, 'maximum' => 100))); |
|
|
|
$cellphone = $sectionInfo->createElement('cellphone', 'TYPO3.Form:SingleLineText'); |
|
$cellphone->setLabel('Mobile'); |
|
$cellphone->setProperty('elementType', 'tel'); |
|
$cellphone->addValidator(new Validator\LabelValidator()); |
|
$cellphone->addValidator(new Validator\TextValidator()); |
|
$cellphone->addValidator(new Validator\StringLengthValidator(array('minimum' => 0, 'maximum' => 14))); |
|
|
|
$phone = $sectionInfo->createElement('phone', 'TYPO3.Form:SingleLineText'); |
|
$phone->setLabel('Telephone'); |
|
$phone->setProperty('elementType', 'tel'); |
|
$phone->addValidator(new Validator\LabelValidator()); |
|
$phone->addValidator(new Validator\TextValidator()); |
|
$phone->addValidator(new Validator\StringLengthValidator(array('minimum' => 0, 'maximum' => 14))); |
|
|
|
$email = $sectionInfo->createElement('email', 'TYPO3.Form:SingleLineText'); |
|
$email->setLabel('Email'); |
|
$email->setProperty('required', 'required'); |
|
$email->setProperty('elementType', 'email'); |
|
$email->addValidator(new Validator\NotEmptyValidator()); |
|
$email->addValidator(new Validator\EmailAddressValidator()); |
|
|
|
$form->createPage('confirmation', 'TYPO3.Form:PreviewPage'); |
|
|
|
$donateFinisher = new DonateFinisher\DonateFinisher(); |
|
$form->addFinisher($donateFinisher); |
|
|
|
$redirectFinisher = new TYPO3Finisher\RedirectFinisher(); |
|
$redirectFinisher->setOptions(array( |
|
'action' => 'show', |
|
'controller' => 'Frontend\Node', |
|
'package' => 'TYPO3.Neos', |
|
'format' => 'html', |
|
'arguments' => array( |
|
'node' => $factorySpecificConfiguration['documentNode'], |
|
$factorySpecificConfiguration['argumentNamespace'] => array('@action' => 'paymentForm') |
|
) |
|
)); |
|
$form->addFinisher($redirectFinisher); |
|
|
|
return $form; |
|
} |
|
|
|
} |