This renderer allows you to output your form using a Flexy template.
A static and dynamic usage example is available in the
docs/renderers
directory.
The following is an example of using the ObjectFlexy renderer with a simple template.
Defining the elements
<?php
require_once 'HTML/Template/Flexy.php';
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/ObjectFlexy.php';
// Form name will be used to find the placeholders.
$form = new HTML_QuickForm('form', 'POST');
// Personal information
$form->addElement('header', 'personal', 'Personal Information');
$form->addElement('text', 'email', 'Your email:');
$form->addElement('password', 'pass', 'Your password:', 'size=10');
$name['last'] = &HTML_QuickForm::createElement('text', 'first', 'First', 'size=10');
$name['first'] = &HTML_QuickForm::createElement('text', 'last', 'Last', 'size=10');
$form->addGroup($name, 'name', 'Name:', ', ');
$areaCode = &HTML_QuickForm::createElement('text', '', null,'size=4 maxlength=3');
$phoneNo1 = &HTML_QuickForm::createElement('text', '', null, 'size=4 maxlength=3');
$phoneNo2 = &HTML_QuickForm::createElement('text', '', null, 'size=5 maxlength=4');
$form->addGroup(array($areaCode, $phoneNo1, $phoneNo2), 'phone', 'Telephone:', '-');
// Company information
$form->addElement('header', 'company_info', 'Company Information');
$form->addElement('text', 'company', 'Company:', 'size=20');
$str[] = &HTML_QuickForm::createElement('text', '', null, 'size=20');
$str[] = &HTML_QuickForm::createElement('text', '', null, 'size=20');
$form->addGroup($str, 'street', 'Street:', '<br />');
$addr['zip'] = &HTML_QuickForm::createElement('text', 'zip', 'Zip', 'size=6 maxlength=10');
$addr['city'] = &HTML_QuickForm::createElement('text', 'city', 'City', 'size=15');
$form->addGroup($addr, 'address', 'Zip, city:');
$select = array('' => 'Please select...', 'AU' => 'Australia', 'FR' => 'France', 'DE' => 'Germany', 'IT' => 'Italy');
$form->addElement('select', 'country', 'Country:', $select);
// Other elements
$form->addElement('checkbox', 'news', '', " Check this box if you don't want to receive our newsletter.");
$form->addElement('reset', 'reset', 'Reset');
$form->addElement('submit', 'submit', 'Register');
// Tries to validate the form
if ($form->validate()) {
// Form is validated, then freezes the data
$form->freeze();
}
// setup a template object
$options = &PEAR::getStaticProperty('HTML_Template_Flexy','options');
$options = array(
'templateDir' => './templates',
'compileDir' => './templates/build',
'forceCompile' => 1,
'debug' => 0,
'local' => 'en'
);
$template = new HTML_Template_Flexy($options);
$renderer =& new HTML_QuickForm_Renderer_ObjectFlexy($template);
$renderer->setLabelTemplate("label.html");
$renderer->setHtmlTemplate("html.html");
$form->accept($renderer);
$view = new StdClass;
$view->form = $renderer->toObject();
$template->compile("flexy-static.html");
$template->outputObject($view);
?>
The template files used above are the following:
label.html
A template for the labels
html.html
A template for the overall html
flexy-static.html
A template for the form
For more information on Flexy templating, see the package homepage.