views:

33

answers:

1

Hi,

How we should use zend view helper form with validators + filters?

Example that miss validators + filters from: http://framework.zend.com/manual/en/zend.view.helpers.html

<form action="action.php" method="post">
 <p>
  <label>Your Email:
   <?php echo $this->formText('email', '[email protected]', array('size' => 32)) ?>
  </label>
 </p>
 <p>
  <label>Your Country:    
   <?php echo $this->formSelect('country', 'us', null, $this->countries) ?>    
  </label>
 </p>
 <p>
  <label>Would you like to opt in?
   <?php echo $this->formCheckbox('opt_in', 'yes', null, array('yes', 'no')) ?>
  </label>
 </p>
</form>

Thanks,

+1  A: 

Create the form as a separate class and then you can use all the validators and filters you wish. There's complete setup info in the docs:

http://framework.zend.com/manual/en/zend.form.quickstart.html

Example from docs:

$form = new Zend_Form();
$form->setAction('/user/login')
     ->setMethod('post');

// Create and configure username element:
$username = $form->createElement('text', 'username');
$username->addValidator('alnum')
         ->addValidator('regex', false, array('/^[a-z]+/'))
         ->addValidator('stringLength', false, array(6, 20))
         ->setRequired(true)
         ->addFilter('StringToLower');

// Create and configure password element:
$password = $form->createElement('password', 'password');
$password->addValidator('StringLength', false, array(6))
         ->setRequired(true);

// Add elements to form:
$form->addElement($username)
     ->addElement($password)
     // use addElement() as a factory to create 'Login' button:
     ->addElement('submit', 'login', array('label' => 'Login'));
Ashley
Thanks, but i asked about view helper form, not how create in regular way zend form
Yosef