Advertisement
Eddz

Untitled

Sep 4th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.37 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Fcm\Form;
  4.  
  5. use Zend\Form\Form;
  6. use Zend\Form\Element;
  7. use Zend\InputFilter\InputFilterProviderInterface;
  8. use Zend\ServiceManager\ServiceManager;
  9.  
  10. class ClientAdd extends Form implements InputFilterProviderInterface
  11. {
  12.  
  13.     protected $repository;
  14.  
  15.     public function __construct($repository)
  16.     {
  17.         $this->repository = $repository;
  18.  
  19.         parent::__construct();
  20.         $this->setName('add-client');
  21.         $this->setAttribute('action', '/clients/add');
  22.         $this->setAttribute('method', 'post');
  23.  
  24.  
  25.         //Fieldset One
  26.         $this->add(array(
  27.             'name' => 'fsOne',
  28.             'type' => 'Zend\Form\Fieldset',
  29.             'options' => array(
  30.                 'legend' => 'Client informations',
  31.             ),
  32.             'elements' => array(
  33.                 // Name
  34.                 array(
  35.                     'spec' => array(
  36.                         'name' => 'name',
  37.                         'type' => 'Zend\Form\Element\Text',
  38.                         'attributes' => array(
  39.                         ),
  40.                         'options' => array(
  41.                             'label' => 'Client name',
  42.                         ),
  43.                     ),
  44.                 ),
  45.                 // Website
  46.                 array(
  47.                     'spec' => array(
  48.                         'name' => 'website',
  49.                         'type' => 'Zend\Form\Element\Text',
  50.                         'attributes' => array(
  51.                         ),
  52.                         'options' => array(
  53.                             'label' => 'Website',
  54.                             'prependText' => 'http://',
  55.                         ),
  56.                     ),
  57.                 ),
  58.                 // Contact
  59.                 array(
  60.                     'spec' => array(
  61.                         'name' => 'contact',
  62.                         'type' => 'Zend\Form\Element\Text',
  63.                         'attributes' => array(
  64.                         ),
  65.                         'options' => array(
  66.                             'label' => 'Contact client',
  67.                         ),
  68.                     ),
  69.                 ),
  70.                 // Email
  71.                 array(
  72.                     'spec' => array(
  73.                         'name' => 'email',
  74.                         'type' => 'Zend\Form\Element\Email',
  75.                         'attributes' => array(
  76.                             'required' => 'required'
  77.                         ),
  78.                         'options' => array(
  79.                             'label' => 'Email',
  80.                         ),
  81.                     ),
  82.                 ),
  83.                 // Phone
  84.                 array(
  85.                     'spec' => array(
  86.                         'name' => 'phone',
  87.                         'type' => 'Zend\Form\Element\Text',
  88.                         'attributes' => array(
  89.                         ),
  90.                         'options' => array(
  91.                             'label' => 'Phone number',
  92.                         ),
  93.                     ),
  94.                 ),
  95.                 // Comment
  96.                 array(
  97.                     'spec' => array(
  98.                         'name' => 'comment',
  99.                         'type' => 'Zend\Form\Element\Textarea',
  100.                         'attributes' => array(
  101.                         ),
  102.                         'options' => array(
  103.                             'label' => 'Comment',
  104.                         ),
  105.                     ),
  106.                 ),
  107.             ),
  108.         ));
  109.  
  110.         //Csrf
  111.         $this->add(new Element\Csrf('csrf'));
  112.  
  113.         //Submit button
  114.         $this->add(array(
  115.             'name' => 'submitBtn',
  116.             'type' => 'Zend\Form\Element\Submit',
  117.             'attributes' => array(
  118.                 'value' => 'Add client',
  119.             ),
  120.             'options' => array(
  121.                 'primary' => true,
  122.             ),
  123.         ));
  124.  
  125.         //Reset button
  126.         $this->add(array(
  127.             'name' => 'resetBtn',
  128.             'attributes' => array(
  129.                 'type' => 'reset',
  130.                 'value' => 'Reset',
  131.             ),
  132.         ));
  133.  
  134.         // Add an element
  135. //        $this->add(array(
  136. //            'type' => 'Zend\Form\Element\Email',
  137. //            'name' => 'email',
  138. //            'options' => array(
  139. //                'label' => 'Email'
  140. //            ),
  141. //            'attributes' => array(
  142. //                'required' => 'required'
  143. //            )
  144. //        ));
  145.     }
  146.  
  147.     public function getInputFilterSpecification()
  148.     {
  149.         return array(
  150.             'fsOne' => array(
  151.                 'spec' => array(
  152.                     'email' => array(
  153.                         'validators' => array(
  154.                             array(
  155.                                 'name' => 'DoctrineModule\Validator\NoObjectExists',
  156.                                 'options' => array(
  157.                                     'object_repository' => $this->repository,
  158.                                     'fields' => 'email',
  159.                                 ),
  160.                                 'messages' => array(
  161.                                     'objectFound' => 'Sorry guy, a user with this email already exists !'
  162.                                 )
  163.                             )
  164.                         )
  165.                     )
  166.                 )
  167.             )
  168.         );
  169.     }
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement