Created
November 13, 2012 14:39
-
-
Save basz/4066068 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace SndCompositionTool\Form; | |
| use SndCompositionTool\Entity\PreOrder as PreOrderEntity; | |
| use Zend\Form\Form; | |
| use Zend\InputFilter\InputFilter; | |
| use Zend\InputFilter\InputFilterProviderInterface; | |
| use Zend\Stdlib\Hydrator\ObjectProperty as Hydrator; | |
| class PreOrder extends Form | |
| { | |
| /** | |
| * @param null|int|string $name Optional name for the element | |
| * @param array $options Optional options for the element | |
| */ | |
| public function __construct($name = 'pre-order', $options = array()) | |
| { | |
| parent::__construct($name, $options); | |
| $factory = new \Zend\InputFilter\Factory(); | |
| $inputFilter = $factory->createInputFilter($this->getInputFilterSpecification()); | |
| $this->setAttribute('method', 'post') | |
| ->setHydrator(new Hydrator()) | |
| ->setInputFilter($inputFilter); | |
| $this->add(array( | |
| 'name' => 'name', | |
| 'type' => 'Zend\Form\Element\Text', | |
| 'options' => array( | |
| 'label' => 'Name', | |
| ), | |
| 'attributes' => array( | |
| 'required' => 'required' | |
| ) | |
| )); | |
| $this->add(array( | |
| 'name' =>'email', | |
| 'type' => 'Zend\Form\Element\Email', | |
| 'options' => array( | |
| 'label' => 'Email', | |
| ), | |
| 'attributes' => array( | |
| 'required' => 'required' | |
| ) | |
| )); | |
| $this->add(array( | |
| 'name' => 'postcode', | |
| 'type' => 'Zend\Form\Element\Text', | |
| 'options' => array( | |
| 'label' => 'Postcode', | |
| 'description' => 'Used to suggest a specialist near you', | |
| ), | |
| 'attributes' => array( | |
| ) | |
| )); | |
| $this->add(array( | |
| 'name' => 'composition', | |
| 'type' => 'Zend\Form\Element\Hidden', | |
| 'attributes' => array( | |
| 'required' => 'required' | |
| ) | |
| )); | |
| $this->add(array( | |
| 'type' => 'Zend\Form\Element\Csrf', | |
| 'name' => 'csrf' | |
| )); | |
| $this->add(array( | |
| 'name' => 'action[]', | |
| 'type' => 'Zend\Form\Element\Button', | |
| 'attributes' => array( | |
| 'value' => 'submit', | |
| 'type' => 'submit', | |
| ), | |
| 'options' => array( | |
| 'label' => 'Order', 'primary' => true, | |
| ), | |
| )); | |
| $this->add(array( | |
| 'name' => 'action[]', | |
| 'type' => 'Zend\Form\Element\Button', | |
| 'attributes' => array( | |
| 'value' => 'modify', | |
| 'type' => 'submit', | |
| ), | |
| 'options' => array( | |
| 'label' => 'Modify' | |
| ), | |
| )); | |
| // $this->add(array( | |
| // 'name' => 'restart', | |
| // 'type' => 'Zend\Form\Element\Button', | |
| // 'attributes' => array( | |
| // 'value' => 'Restart', | |
| // ), | |
| // 'options' => array( | |
| // 'primary' => false, | |
| // 'label' => 'Restart' | |
| // ), | |
| // )); | |
| $this->setValidationGroup(array( | |
| 'csrf', | |
| 'composition', | |
| 'name', | |
| 'email', | |
| 'postcode', | |
| ) | |
| ); | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public function getInputFilterSpecification() | |
| { | |
| return array( | |
| 'name' => array( | |
| 'required' => true, | |
| ), | |
| 'email' => array( | |
| 'required' => true, | |
| 'validators' => array( | |
| array( | |
| 'name' => 'EmailAddress', | |
| 'options' => array( | |
| 'message' => 'The supplied email address is not a valid', | |
| ) | |
| ) | |
| ), | |
| ), | |
| 'composition' => array( | |
| 'required' => true, | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment