Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Fcm\Form;
- use Zend\Form\Form;
- use Zend\Form\Element;
- use DoctrineModule\Validator\NoObjectExists as NoObjectExistsValidator;
- class ClientAdd extends Form
- {
- protected $repository;
- public function __construct($repository)
- {
- $this->repository = $repository;
- parent::__construct();
- $this->setName('add-client');
- $this->setAttribute('action', '/clients/add');
- $this->setAttribute('method', 'post');
- //Fieldset One
- $this->add(array(
- 'name' => 'fsOne',
- 'type' => 'Zend\Form\Fieldset',
- 'options' => array(
- 'legend' => 'Client informations',
- ),
- 'elements' => array(
- // Name
- array(
- 'spec' => array(
- 'name' => 'name',
- 'type' => 'Zend\Form\Element\Text',
- 'attributes' => array(
- ),
- 'options' => array(
- 'label' => 'Client name',
- ),
- ),
- ),
- // Website
- array(
- 'spec' => array(
- 'name' => 'website',
- 'type' => 'Zend\Form\Element\Text',
- 'attributes' => array(
- ),
- 'options' => array(
- 'label' => 'Website',
- 'prependText' => 'http://',
- ),
- ),
- ),
- // Contact
- array(
- 'spec' => array(
- 'name' => 'contact',
- 'type' => 'Zend\Form\Element\Text',
- 'attributes' => array(
- ),
- 'options' => array(
- 'label' => 'Contact client',
- ),
- ),
- ),
- // Email
- array(
- 'spec' => array(
- 'name' => 'email',
- 'type' => 'Zend\Form\Element\Email',
- 'attributes' => array(
- 'required' => 'required'
- ),
- 'options' => array(
- 'label' => 'Email',
- ),
- ),
- ),
- // Phone
- array(
- 'spec' => array(
- 'name' => 'phone',
- 'type' => 'Zend\Form\Element\Text',
- 'attributes' => array(
- ),
- 'options' => array(
- 'label' => 'Phone number',
- ),
- ),
- ),
- // Comment
- array(
- 'spec' => array(
- 'name' => 'comment',
- 'type' => 'Zend\Form\Element\Textarea',
- 'attributes' => array(
- ),
- 'options' => array(
- 'label' => 'Comment',
- ),
- ),
- ),
- ),
- ));
- //Csrf
- $this->add(new Element\Csrf('csrf'));
- //Submit button
- $this->add(array(
- 'name' => 'submitBtn',
- 'type' => 'Zend\Form\Element\Submit',
- 'attributes' => array(
- 'value' => 'Add client',
- ),
- 'options' => array(
- 'primary' => true,
- ),
- ));
- //Reset button
- $this->add(array(
- 'name' => 'resetBtn',
- 'attributes' => array(
- 'type' => 'reset',
- 'value' => 'Reset',
- ),
- ));
- // Add an element
- $this->add(array(
- 'type' => 'Zend\Form\Element\Email',
- 'name' => 'email',
- 'options' => array(
- 'label' => 'Email'
- ),
- 'attributes' => array(
- 'required' => 'required'
- )
- ));
- // Now get the input filter of the form, and add the validator to the email input
- $emailInput = $this->getInputFilter()->get('email');
- $noObjectExistsValidator = new NoObjectExistsValidator(array(
- 'object_repository' => $this->repository,
- 'fields' => 'email'
- ));
- $emailInput->getValidatorChain()
- ->addValidator($noObjectExistsValidator);
- }
- // public function getInputFilterSpecification()
- // {
- //// die(var_dump($this->serviceManager->getRepository('Fcm\Entity\Client')->checkIfEmailExists("[email protected]"))); // !!! WORKS
- // return array(
- // 'email' => array(
- // 'validators' => array(
- // array(
- // 'name' => 'DoctrineModule\Validator\NoObjectExists',
- // 'options' => array(
- // 'object_manager' => $this->repository,
- // 'fields' => 'email'
- // )
- // )
- // )
- // )
- // );
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement