怎么样才能在Smarty模板上显示QuickForm下创建的单选按钮?还有如何让QuickForm的AddRule所设置的规范有效显示呢?我想要在Smarty模板上没有填写某个必填信息来给予错误提示(错误提示就显示在所在文本框之上)
我的程序:
php:<?php
header("Content-Type: text/html; charset=gb2312"); require_once "HTML/QuickForm.php";
require_once "HTML/QuickForm/Renderer/ArraySmarty.php";
require_once 'd:\xampp\php\Smarty\libs\Smarty.class.php'; $smarty = new Smarty();
$smarty->template_dir = "D:/xampp/php/Smarty/demo/templates";
$smarty->compile_dir = "D:/xampp/php/Smarty/demo/compile_dir";
$smarty->config_dir = "D:/xampp/php/Smarty/demo/configs";
$smarty->cache_dir = "D:/xampp/php/Smarty/demo/cache";

$smarty->assign("CSSDIR", "D:/xampp/htdocs/Project/CSS");
$smarty->assign("title", "::用户注册页面::");

$form = new HTML_QuickForm("registerFrm", "post");
$country = array(
"1" => "中国",
"2" => "日本",
"3" => "美国",
"4" => "英国",
"0" => "其它"
);
$city = array(
 "1" => "北京",
 "2" => "广东",
 "3" => "江西",
 "0" => "其它"
 );
$industry = array(
"1" => "学生",
"2" => "科研机构",
"3" => "IT产业",
"0" => "其它"
 );
$from = array(
"1" => "网吧",
"2" => "单位",
"3" => "家里",
"0" => "其它"
 );
$form->setDefaults(
array(
"openornot" => 1,
"idtype" => 1,
"secret" => 1
 )
  );

$form->addElement("text", "name", "", array("size" => 20, "maxlength" => 20));
$form->addElement("password", "pass", "", array("size" => 20, "maxlength" => 20));
$form->addElement("password", "repass", "", array("size" => 20, "maxlength" => 20));
$form->addElement("text", "email", "", array("size" => 20, "maxlength" => 50));
$form->addElement("text", "passquestion", "", array("size" => 50, "maxlength" => 50));
$form->addElement("text", "passanswer", "", array("size" => 50, "maxlength" => 50));
$form->addElement("text", "alias", "", array("size" => 30, "maxlength" => 50));
$form->addElement("textarea", "description", "", array("rows" => 3, "cols" => 50, "class" => "textBox"));

$radio[] = $form->createElement("radio", "openornot", null, "以下信息对外不公开", null, array('value' => 1, 'checked' => 'true'));
$radio[] = $form->createElement("radio", "openornot", null, "以下信息对外公开", null, array('value' => 2));
$form->addGroup($radio, "secret");

$form->addElement('text', 'idnuber', '证件号码:', array('size' => 30, 'maxlength' => 30));

$radio2[] =  $form->createElement('radio', 'idtype', null, '身份证', null, array('value' => 1, 'checked' => 'true'));
$radio2[] =  $form->createElement('radio', 'idtype', null, '其它证件', null, array('value' => 2));
$form->addGroup($radio2);

$form->addElement('text', 'realname', '', array('size' => 20, 'maxlength' => 30));
$form->addElement('select', 'gender', '', array('male' => '男', 'female' => '女'));
$form->addElement('date', 'born', '', array('format' => 'Y 年m 月d', 'minYear' => 1940, 'maxYear' => 1995));
$form->addElement('select', 'country', '', $country);
$form->addElement('select', 'city', '', $city);
$form->addElement('text', 'town', '', array('size' => 20, 'maxlength' => 20));
$form->addElement('text', 'address', '', array('size' => 50, 'maxlength' => 50));
$form->addElement('text', 'zipcode', '', array('size' => 20, 'maxlength' => 20));
$form->addElement('text', 'phone', '', array('size' => 20, 'maxlength' => 20));
$form->addElement('text', 'company', '', array('size' => 30, 'maxlength' => 30));
$form->addElement('text', 'department', '', array('size' => 20, 'maxlength' => 20));
$form->addElement('select', 'industry', '', $industry);
$form->addElement('select', 'source', '', $from);
$form->addElement('text', 'webpage', '', array('size' => 50, 'maxlength' => 50));
$form->addElement('submit', "btnSubmit", '注册用户');

$form->applyFilter('name', 'trim');
$form->addRule('name', '用户登录昵称必须填写!!', 'required');
$form->addRule('pass', '密码不能为空', 'required');
$form->addRule('email', '电子邮件EMAIL不能为空', 'required');
$form->addRule('passquestion', '请填写密码提示问题', 'required');
$form->addRule('passanswer', '请填写密码提示答案', 'required');
$form->addRule('idnuber', '请填写证件号码', 'required');
$form->addRule('realname', '请填写真实姓名', 'required');
$form->addRule('gender', '性别不能为空', 'required');
$form->addRule('born', '出生日期不能为空', 'required');
$form->addRule('country', '国家不能为空', 'required');
$form->addRule('city', '城市不能为空', 'required');
$form->addRule('address', '请填写你的联系地址', 'required');
 
$form->addRule('name', '用户登录呢称最少为5个字符', 'minlength', 5);
$form->addRule('pass', '密码太简单,不能少于5位', 'minlength', 5);
$form->addRule(array('pass', 'repass'), '两次的密码不一致', 'compare');
$form->addRule('email', '请输入正确的EMAIL地址(user@domain)', 'email');
$form->addRule('idnuber', '证件号码不能少于5位', 'minlength', 5);
$form->addRule('idnuber', '证件号码只能是英文字母或数字', 'alphanumeric');
$form->registerRule('keyword', 'function', 'checkUser');
$form->addRule('name', '用户名已经存在,请重新选择', 'keyword');

function checkUser($elementName, $elementValue) {
$keywords = array("admin", "administrator", "webmaster", "supervisor");
if (in_array($elementValue, $keywords))
return false;
else
return true;
}

if ($form->validate())
$form->process("exportValues");
else {
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$form->accept($renderer);

$smarty->assign("form_data", $renderer->toArray());
$smarty->caching = false;

$smarty->display("register.tpl");
}

function exportValues($data) {
echo("<pre>");
print_r($data);
echo("</pre>");
}
?>