1<?php 2/** 3* Example of usage for HTML_QuickForm with ITDynamic renderer (2-column layout) 4* 5* @category HTML 6* @package HTML_QuickForm 7* @author Adam Daniel <adaniel1@eesus.jnj.com> 8* @author Bertrand Mansion <bmansion@mamasam.com> 9* @author Alexey Borzov <avb@php.net> 10* @version CVS: $Id$ 11* @ignore 12*/ 13require_once 'HTML/QuickForm.php'; 14require_once 'HTML/QuickForm/Renderer/ITDynamic.php'; 15// can use either HTML_Template_Sigma or HTML_Template_ITX 16require_once 'HTML/Template/ITX.php'; 17//require_once 'HTML/Template/Sigma.php'; 18 19$form = new HTML_QuickForm('frmTest', 'POST'); 20 21// Fills with some defaults values 22$defaultValues['company'] = 'Mamasam'; 23$defaultValues['country'] = array(); 24$defaultValues['name'] = array('first'=>'Alexey', 'last'=>'Borzov'); 25$defaultValues['phone'] = array('513', '123', '4567'); 26$form->setDefaults($defaultValues); 27 28// Hidden 29$form->addElement('hidden', 'session', '1234567890'); 30$form->addElement('hidden', 'timer', '12345'); 31$form->addElement('hidden', 'ihidTest', 'hiddenField'); 32 33// Personal information 34$form->addElement('header', 'personal_info', 'Personal Information'); 35 36$name['last'] = &HTML_QuickForm::createElement('text', 'first', 'First', 'size=10'); 37$name['first'] = &HTML_QuickForm::createElement('text', 'last', 'Last', 'size=10'); 38$form->addGroup($name, 'name', 'Name:', ', '); 39 40$areaCode = &HTML_QuickForm::createElement('text', '', null,'size=4 maxlength=3'); 41$phoneNo1 = &HTML_QuickForm::createElement('text', '', null, 'size=4 maxlength=3'); 42$phoneNo2 = &HTML_QuickForm::createElement('text', '', null, 'size=5 maxlength=4'); 43$form->addGroup(array($areaCode, $phoneNo1, $phoneNo2), 'phone', 'Telephone:', '-'); 44 45$form->addElement('text', 'email', 'Your email:'); 46 47$form->addElement('password', 'pass', 'Your password:', 'size=10'); 48 49// to finish the first column: 50$form->addElement('static', null, null, 'first column'); 51 52 53// Company information 54$form->addElement('header', 'company_info', 'Company Information'); 55 56$form->addElement('text', 'company', 'Company:', 'size=20'); 57 58$str[] = &HTML_QuickForm::createElement('text', '', null, 'size=20'); 59$str[] = &HTML_QuickForm::createElement('text', '', null, 'size=20'); 60$form->addGroup($str, 'street', 'Street:', '<br />'); 61 62 63$addr['zip'] = &HTML_QuickForm::createElement('text', 'zip', 'Zip', 'size=6 maxlength=10'); 64$addr['city'] = &HTML_QuickForm::createElement('text', 'city', 'City', 'size=15'); 65$form->addGroup($addr, 'address', 'Zip, city:'); 66 67$select = array('' => 'Please select...', 'AU' => 'Australia', 'FR' => 'France', 'DE' => 'Germany', 'IT' => 'Italy'); 68$form->addElement('select', 'country', 'Country:', $select); 69 70// Creates a checkboxes group using an array of separators 71$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'A', null, 'A'); 72$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'B', null, 'B'); 73$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'C', null, 'C'); 74$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'D', null, 'D'); 75$form->addGroup($checkbox, 'destination', 'Destination:', array(' ', '<br />')); 76 77// to finish the second column: 78$form->addElement('static', null, null, 'second column'); 79 80// can't render these elements properly, so they are in the template 81//$form->addElement('reset', 'reset', 'Reset'); 82//$form->addElement('submit', 'submit', 'Register'); 83 84// Adds some validation rules 85$form->addRule('email', 'Email address is required', 'required'); 86$form->addGroupRule('name', 'Name is required', 'required'); 87$form->addRule('pass', 'Password must be between 8 to 10 characters', 'rangelength', array(8, 10)); 88$form->addRule('country', 'Country is a required field', 'required'); 89$form->addGroupRule('destination', 'Please check at least two boxes', 'required', null, 2); 90$form->addGroupRule('phone', 'Please fill all phone fields', 'required'); 91$form->addGroupRule('phone', 'Values must be numeric', 'numeric'); 92 93 94$AddrRules['zip'][0] = array('Zip code is required', 'required'); 95$AddrRules['zip'][1] = array('Zip code is numeric only', 'numeric'); 96$AddrRules['city'][0] = array('City is required', 'required'); 97$AddrRules['city'][1] = array('City is letters only', 'lettersonly'); 98$form->addGroupRule('address', $AddrRules); 99 100// Tries to validate the form 101if ($form->validate()) { 102 // Form is validated, then freezes the data 103 $form->freeze(); 104} 105 106 107// can use either HTML_Template_Sigma or HTML_Template_ITX 108$tpl =& new HTML_Template_ITX('./templates'); 109// $tpl =& new HTML_Template_Sigma('./templates'); 110 111$tpl->loadTemplateFile('it-dynamic-2.html'); 112 113$renderer =& new HTML_QuickForm_Renderer_ITDynamic($tpl); 114$renderer->setElementBlock(array( 115 'name' => 'qf_group_table', 116 'address' => 'qf_group_table' 117)); 118 119$form->accept($renderer); 120 121$tpl->show(); 122?> 123