Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php zend形式的验证_Php_Zend Framework_Zend Form - Fatal编程技术网

Php zend形式的验证

Php zend形式的验证,php,zend-framework,zend-form,Php,Zend Framework,Zend Form,在Zend表单中使用“更改密码”时,我想检查旧密码和新密码。两者不应相同。Zend表单中是否有任何选项可以同时检查两者 提前感谢。在“我的”下创建一个库,并使用以下内容: class My_Validate_PasswordConfirmation extends Zend_Validate_Abstract { const NOT_MATCH = 'notMatch'; protected $_messageTemplates = array( self::

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


提前感谢。

在“我的”下创建一个库,并使用以下内容:

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;
    }
}
向下滚动到或查找:

注意:验证上下文

在源页面上。代码就在下面,解释也在下面


希望有帮助!:)

在控制器或模型代码中处理表单时执行此操作。它应该只是比较新哈希和旧哈希,以确保它们不匹配。