Quicker and cleaner Form using Zend Form

Usually handing forms involves coding the form in HTML and performing client and server side validation, which usually makes the code for complex forms quite unwieldy. Zend_Form which is available in Zend Framework version 1.5 aims at simplifying this process.
You can now create and add methods for validating form fields completely in Zend_Form. Here’s an example from an article at Zend Developer Zone:
$form = new Zend_Form; $form->setAction('/resource/process') ->setMethod('post') ->setAttrib('id', 'login'); $username = new Zend_Form_Element_Text('username'); $username->addValidator('alnum') ->addValidator('regex', false, array('/^[a-z]/i')) ->setRequired(true) ->addFilter('StringToLower'); $form->addElement($username); $password = new Zend_Form_Element_Password('password'); $password->addValidator('stringLength', false, array(6)) ->setRequired(true) $form->addElement($password); $form->addElement(new Zend_Form_Element_Submit()); |
To learn more on this head over to the Zend_Form Quick start guide at : http://framework.zend.com/manual/en/zend.form.quickstart.html or an article by Cal Evans at Zend Developer Zone: Lifting the Skirt on Zend Framework 1.5 - Zend_Form




















2 Responses to “Quicker and cleaner Form using Zend Form”
By vinu on Feb 13, 2008 | Reply
A few more advanced form techniques using Zend Framework are available at: http://gourl.in/0j