1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <?php
require_once "HTML/QuickForm.php";
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
require_once 'Smarty.class.php';
$form = new HTML_QuickForm('frmTest', 'get');
$form->addElement('header', 'hdrTesting', 'Testing Smarty');
$form->addElement('text', 'txtFirstName', 'First name?');
$form->addElement('text', 'txtLastName', 'Last name?');
$form->addElement('text', 'txtAge', 'Age?');
$form->addElement('text', 'txtTelephone', 'Telephone number?');
$form->addElement('reset', 'btnClear', 'Clear');
$form->addElement('submit', 'btnSubmit', 'Submit');
if ($form->validate()) {
# If the form validates then freeze the data
$form->freeze();
}
// Create the template object
$tpl =& new Smarty;
$tpl->template_dir = '.';
$tpl->compile_dir = '/tmp';
// Create the renderer object
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl);
// build the HTML for the form
$form->accept($renderer);
// assign array with form data
$tpl->assign('form_data', $renderer->toArray());
// parse and display the template
$tpl->display('smarty1.tpl');
?> |
Partager