0

在 Zend Form 中使用更改密码时,我想检查旧密码和新密码。两者不应该相同。Zend Form 中是否有任何选项可以检查两者。

提前致谢。

4

1 回答 1

1

在 My 下创建一个库并使用以下内容:

class My_Validate_PasswordConfirmation extends Zend_Validate_Abstract
{
    const NOT_MATCH = 'notMatch';
 
    protected $_messageTemplates = array(
        self::NOT_MATCH => 'Password confirmation does not match'
    );
 
    public function isValid($value, $context = null)
    {
        $value = (string) $value;
        $this->_setValue($value);
 
        if (is_array($context)) {
            if (isset($context['password_confirm'])
                && ($value == $context['password_confirm']))
            {
                return true;
            }
        } elseif (is_string($context) && ($value == $context)) {
            return true;
        }
 
        $this->_error(self::NOT_MATCH);
        return false;
    }
}

更多信息请参阅: Zend 手册 向下滚动或查找:

注意:验证上下文

在源页面上。代码在它的正下方给出,解释也是如此。

希望能帮助到你!:)

于 2012-08-14T06:31:35.260 回答