Php zend形式的验证
在Zend表单中使用“更改密码”时,我想检查旧密码和新密码。两者不应相同。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::
提前感谢。在“我的”下创建一个库,并使用以下内容:
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;
}
}
向下滚动到或查找:
注意:验证上下文
在源页面上。代码就在下面,解释也在下面
希望有帮助!:) 在控制器或模型代码中处理表单时执行此操作。它应该只是比较新哈希和旧哈希,以确保它们不匹配。