Search code examples
phpformspear

Is there a way to make a custom rule in QuickForm2 the same way as it was done in QuickForm using addFormRule


In QuickForm it could be done kind of like this:

$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');

But QuickForm2 does not seem to have addFormRule(), is there anything replacing it?


Solution

  • Found the answer:

    function chkPass($password)
    {
        return ($password == 'qwerty');
    }
    $oldpassword->createRule('callback', 'Old password does not match your records.', 'chkPass')