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 Zend\InputFilter\InputFilterProviderInterface;
- use Zend\ServiceManager\ServiceManager;
- class ClientAdd extends Form implements InputFilterProviderInterface
- {
- 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',
- ),
- ));
- }
- public function getInputFilterSpecification()
- {
- // die(var_dump($this->repository->checkIfEmailExists("test@test.com"))); // !!! WORKS
- return array(
- 'elements' => array(
- // Name
- array(
- 'spec' => array(
- 'name' => 'email',
- 'validators' => array(
- array(
- 'name' => 'DoctrineModule\Validator\NoObjectExists',
- 'options' => array(
- 'object_repository' => $this->repository,
- 'fields' => 'email',
- ),
- 'messages' => array(
- 'objectFound' => 'Sorry guy, a user with this email already exists !'
- )
- )
- )
- ),
- ),
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement