0

我一直在为此奋斗了一个小时,仍然无法理解错误。
以下是我设置我的两个领域:Zend_Form:相同的字段实际上相同时返回false

$password = $this->createElement('password', 'password'); 
$password->setLabel('Password'); 
$password->setRequired('true'); 
$password->addValidator(new Zend_Validate_Regex('/^([a-zA-Z0-9]*[0-9]+[a-z]*[A-Z]+[a-zA-Z0-9]*)|([a-zA-Z0-9]*[A-Z]+[a-z]*[0-9]+[a-zA-Z0-9]*)$/')); 
$password->setAttrib('size', 25); 
$password->setAttrib('length', 150); 
$this->addElement($password); 

$confirm_password = $this->createElement('password', 'confirm_password'); 
$confirm_password->setLabel('Confirm'); 
$confirm_password->setRequired('true'); 
$confirm_password->setAttrib('size', 25); 
$confirm_password->setAttrib('length', 150); 

$confirm_password->addValidator('Identical', false, array('token' => 'password')); 
//$confirm_password->addValidator(new Zend_Validate_Identical(array('token' => 'password'))); 

$this->addElement($confirm_password); 

我都试过验证(+的一个注释),但没有工作。 这些声明来自www.wjgilmore.com/blog/entry/validating_identical_passwords_with_the_zend_frameworkhttps://stackoverflow.com/a/3653416/1300454

两个声明总是返回“两个给定的标记不匹配”事件我确定这两个字段包含完全相同的字符串。

任何猜测?谢谢!

编辑: 只是注意到多亏了XDebug,当Zend_Validate_IdenticalisValid()函数被调用时,我$token等于‘密码’,而我$value等于‘P4ssword’(我在confirm_password字段中输入的密码,这是怎么回事。 ?

EDIT2: 试图与这两个解决方案:emanaton.com/code/php/validateidenticalfieldstackoverflow.com/a/1628611/1300454,但他们没有为我工作或者与通用IdenticalField验证它不能找到我的“密码”栏和第二确认刚刚返回。两个领域不匹配,并与XDebug的再次我发现它仍然希望我的密码“P4ssword”匹配单词“密码”,我给作为字段名称...

回答

0

难道你不使用当前的Zend Framework版本?类中的代码看起来应该像你期望的那样工作(1.11)。你使用$ form-> isValid()或 - > isValidPartial()吗?尝试编辑ZF的代码并转储$ context变量的内容。它看起来像你的代码没有填充$ context变量,因为它应该。

public function isValid($value, $context = null) 
{ 
    $this->_setValue((string) $value); 

    if (($context !== null) && isset($context) && array_key_exists($this->getToken(), $context)) { 
     $token = $context[$this->getToken()]; 
    } else { 
     $token = $this->getToken(); 
    } 

    if ($token === null) { 
     $this->_error(self::MISSING_TOKEN); 
     return false; 
    } 

    $strict = $this->getStrict(); 
    if (($strict && ($value !== $token)) || (!$strict && ($value != $token))) { 
     $this->_error(self::NOT_SAME); 
     return false; 
    } 

    return true; 
} 
+0

有没有一种方法可以确定告诉我使用的是什么版本? –

+0

$ context包含: ('controller'=>'user','action'=>'dovalidation','module'=>'default','confirm_password'=>'P4ssword') –

+0

btw,我正在使用ZF v1.11.3 –

相关问题