We are having computer technology lecture frequently at PT.Buzoo Indonesia.
Today topic is about learn Zend Framework.
The section talk about how to use or tutorial Zend Form.
Zend_Form is library in Zend Framework for creating form object.
One of our PHP Team, Tya Herlina, will presenting this section.
We hope all of you guys enjoy this lecture section with this online presentation.
If you want know about PT. Buzoo Indonesia, Please visit our website : http://buzoo.co.id
2. • Zend_Form is library in Zend Framework for creating
form object.
• Why Zend_Form 1.7?
• In Buzoo Indonesia, we use Zend Framework version 1.7
• HOW to?
$form = new Zend_Form();
3. • Simplifies form creation,
• Simplifies form handling in your web application.
4. • Element input filtering and validation
• Element ordering
• Element and Form rendering, including escaping
• Element and form grouping
• Element and form-level configuration
It heavily leverages other Zend Framework components to
accomplish its goals, including :
• Zend_Config
• Zend_Validate
• Zend_Filter
• Zend_Loader_PluginLoader
• Zend_View [optionally]
5. • button
• checkbox
• multicheckbox
• hidden
• image
• password
• radio
• reset
• select
• submit
• text
• textarea
• etc (see
Zend_Form_Element_*)
6. • Alnum
• Alpha
• Date
• Digits
• EmailAddress
• StringLength
• Regex
• Etc (See Zend_Validate_*)
8. • Example ---- We want to register account in :
www.buzoolecture.com/register/form
• Registration Form
• Nickname (Required, Min. 6 char, Max. 10 char, must be Alpha
and Number)
• Gender (Required)
• Phone (Required, must be number)
• Email Address (Required)
• Password (Required)
• Confirmation Password (Required, must be same with Password)
9. • Enables developers to store configuration data in a familiar INI
format and read them in the application by using nested object
property syntax.
$config = new Zend_Config_Ini('/path/to/config.ini',
„section_name„, $options);
• By default, the key separator character is the period character
(.)
• This can be changed :
$options['nestSeparator'] = ':';
• Comments start with (;), as in php.ini
• Zend_Config_Ini utilizes the parse_ini_file() PHP function.
• Example : http://id1.php.net/parse_ini_file
11. public function formAction() {
//get register.ini file
$config = new Zend_Config_Ini(„/path/to/register.ini‟, 'form');
//define form
$form = new Zend_Form($config->register->form);
$this->view->form = $form;
//set option for element gender
$form->getElement('gender')->setMultiOptions(array('1' => 'Male', '2' => 'Female'));
$form->getElement('gender')->setSeparator(' ');
//if submit button pressed
if ( $this->getRequest()->isPost() ) {
//isValid is function from Zend
if ($form->isValid($_POST) ) {
//get value for checking confirmation password must be same with password
if( $form->getValue(„password‟) == $form->getValue(„conf_password‟) ) {
echo “Complete!!”;
} else {
echo “Ups, Sorry! Confirmation Password must be same with Password”;
}
}
}
}