Zend_Form
Zend_Form simplifies form creation and handling in your web application. It performs the following tasks:
- Element input filtering and validation
- Element ordering
- Element and Form rendering, including escaping
- Element and form grouping
- Element and form-level configuration
Zend_Form makes use of several Zend Framework components to accomplish its goals, including Zend_Config, Zend_Validate,Zend_Filter, Zend_Loader_PluginLoader, and optionally Zend_View.
Creating new controller
go to your project in command prompt and type;
zf create controller {controller name}
in my case I will type as;
zf create controller form
a new controller namely formController.php in the project controller directory and with that a new view folder form with index.phtml is also added to the project by zend.
Now we will go to our view file form/index.phtml and create our form. type the following to create form;
<?php
$form = new Zend_Form;
$form->setAction('/index/index')
->setMethod('post');
$firstName = new Zend_Form_Element_Text('firstName');
$firstName->setLabel('First name')
->setRequired(true)
->addValidator('NotEmpty');
$lastName = new Zend_Form_Element_Text('lastName');
$lastName->setLabel('Last name')
->setRequired(true)
->addValidator('NotEmpty');
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email address')
->addFilter('StringToLower')
->setRequired(true)
->addValidator('NotEmpty', true)
->addValidator('EmailAddress');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Contact us');
$form->addElements(array($firstName,
$lastName, $email, $submit));
echo $form;
now go to you site Url and check
No comments:
Post a Comment