sathyashrayan

form

May 14th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.86 KB | None | 0 0
  1. <?php
  2. namespace Application\Form;
  3.  
  4. use Zend\Form\Form;
  5. use Zend\ServiceManager\ServiceLocatorAwareInterface;
  6. use Zend\ServiceManager\ServiceLocatorInterface;
  7. use Zend\ServiceManager\ServiceManager;
  8.  
  9. class DemoForm extends Form implements ServiceLocatorAwareInterface
  10. {
  11.     protected $serviceLocator;
  12.    
  13.     public function getServiceLocator ()
  14.     {
  15.         return $this->serviceLocator;
  16.     }
  17.    
  18.     public function setServiceLocator (ServiceLocatorInterface $serviceLocator)
  19.     {
  20.         $this->serviceLocator = $serviceLocator;
  21.     }
  22.    
  23.     public function init()
  24.     {
  25.         //parent::__construct("Sample Form");
  26.          
  27.         $this->getServiceLocator()->get('ValidatorManager')->getRegisteredServices();
  28.        
  29.         $this->setAttribute('method', 'post');
  30.          
  31.         $this->add(array(
  32.                 'name' => 'id',
  33.                 'attributes' => array(
  34.                         'type'  => 'hidden',
  35.                 ),
  36.         ));
  37.          
  38.         $this->add(array(
  39.                 'name' => 'name',
  40.                 'attributes' => array(
  41.                         'type'  => 'text',
  42.                 ),
  43.                 'options' => array(
  44.                         'label' => 'Name',
  45.                 ),
  46.         ));
  47.          
  48.         $this->add(array(
  49.                 'type' => 'Zend\Form\Element\Select',
  50.                 'name' => 'gender',
  51.                 'options' => array(
  52.                         'label' => 'Gender',
  53.                         'value_options' => array(
  54.                                 '1' => 'Select your gender',
  55.                                 '2' => 'Female',
  56.                                 '3' => 'Male'
  57.                         ),
  58.                 ),
  59.                 'attributes' => array(
  60.                         'value' => '1' //set selected to '1'
  61.                 )
  62.         ));
  63.          
  64.         $this->add(array(
  65.                 'type' => 'Zend\Form\Element\MultiCheckbox',
  66.                 'name' => 'hobby',
  67.                 'options' => array(
  68.                         'label' => 'Please choose one/more of the hobbies',
  69.                         'value_options' => array(
  70.                                 '1' =>'Cooking',
  71.                                 '2'=>'Writing',
  72.                                 '3'=>'Others'
  73.                         ),
  74.                 ),
  75.                 'attributes' => array(
  76.                         'value' => '1' //set checked to '1'
  77.                 )
  78.         ));
  79.          
  80.         $this->add(array(
  81.                 'type' => 'Zend\Form\Element\Email',
  82.                 'name' => 'email',
  83.                 'options' => array(
  84.                         'label' => 'Email'
  85.                 ),
  86.                 'attributes' => array(
  87.                         'placeholder' => 'you@domain.com'
  88.                 )
  89.         ));
  90.    
  91.         $this->add(array(
  92.                 'type' => 'Zend\Form\Element\Date',
  93.                 'name' => 'birth',
  94.                 'options' => array(
  95.                         'label' => 'Birth'
  96.                 )
  97.         ));
  98.          
  99.         $this->add(array(
  100.                 'name' => 'address',
  101.                 'attributes'=>array(
  102.                         'type'=>'textarea'
  103.                 ),
  104.                 'options' => array(
  105.                         'label' => 'Address',
  106.                 ),
  107.         ));
  108.          
  109.         $this->add(array(
  110.                 'type' => 'Zend\Form\Element\Radio',
  111.                 'name' => 'direction',
  112.                 'options' => array(
  113.                         'label' => 'Please choose one of the directions',
  114.                         'value_options' => array(
  115.                                 '1' => 'Programming',
  116.                                 '2' => 'Design',
  117.                         ),
  118.                 ),
  119.                 'attributes' => array(
  120.                         'value' => '1' //set checked to '1'
  121.                 )
  122.         ));
  123.          
  124.         $this->add(array(
  125.                 'name' => 'submit',
  126.                 'attributes' => array(
  127.                         'type'  => 'submit',
  128.                         'value' => 'Go',
  129.                         'id' => 'submitbutton',
  130.                 ),
  131.         ));
  132.        
  133.     }
  134.      
  135.    
  136. }
Add Comment
Please, Sign In to add comment