【问题标题】:Is there a way to make a custom rule in QuickForm2 the same way as it was done in QuickForm using addFormRule有没有办法在 QuickForm2 中创建自定义规则,就像在 QuickForm 中使用 addFormRule 一样
【发布时间】:2012-08-14 13:38:58
【问题描述】:

在 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(),有什么可以替代的吗?

【问题讨论】:

    标签: php forms pear


    【解决方案1】:

    找到答案:

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

    【讨论】:

    • 感谢您的回答。如何以表单形式在 $this 上创建此规则?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-10
    相关资源
    最近更新 更多