在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')

10-02 15:20