在QuickForm中,可以这样进行:
$form = new HTML_QuickForm2('changepassword');
$passwordold = $fs->addElement('password', 'oldpassword')->setLabel('Old password');
function chkPass($fields)
{
if ((strlen($fields['oldpassword']) && (md5($fields['oldpassword'])<>passwordcheck())))
{
return array('oldpassword' => 'Old password does not match your records.');
}
return true;
}
$form->addFormRule('chkPass');
但是QuickForm2似乎没有addFormRule(),有什么替代品吗?
解决方法:
找到了答案:
function chkPass($password)
{
return ($password == 'qwerty');
}
$oldpassword->createRule('callback', 'Old password does not match your records.', 'chkPass')