Smarty provides its own set of handy custom functions for creating form elements.
In most cases you can still use these to draw QuickForm elements, but it's preferable to
use $form.someElement.html instead, because
<?php
require('HTML/QuickForm.php');
require('HTML/QuickForm/Renderer/ArraySmarty.php');
require('./slides/QuickForm_and_Smarty/setup.php');
$ratings = array('superb','marvelous','outstanding','stupendous','fabulous');
$tpl->assign('ratings',$ratings); // for the smarty radio button function
$form = new HTML_QuickForm('ratingForm','POST', $_SERVER['REQUEST_URI']);
$ratingRadios = array();
foreach ($ratings as $r) { // type, name, label,text,value
$ratingRadios[] = $form->createElement('radio',null, null, $r, $r);
}
$form->addGroup($ratingRadios,'rating',null,'<br />');
$form->addGroupRule('rating','Please give us your honest opinion','required');
// custom validation function
function isValidSelection($value,$array) { return in_array($value,$array); }
// ... register custom rule/callback function
$form->registerRule('validateSelection', 'callback', 'isValidSelection');
// ..."add" the rule
$form->addRule('rating','invalid selection','validateSelection',$ratings);
$form->addElement('submit', 'submitRatingButton', 'Submit');
if ($form->validate()) {
$tpl->assign('response','Aw gee, do you really think so?');
}
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($tpl);
$form->accept($renderer);
$tpl->assign('form', $renderer->toArray());
$tpl->display('smarty_vs_qform.tpl');
?>