ZF 1.11.3这里。用Zend_Filter_Input确认相同的密码
$validators = array(
'pass1' => array('presence' => 'required'),
'pass2' => array(array('Identical', true, 'token' => 'pass1'))
),
$input = new Zend_Filter_Input(array(), $validators, $this->_request->getParams());
if (!$input->isValid()) {
var_dump($input->getMessages());
}
使用上面的代码中,我得到(firephp格式,实际上):
['pass2'] =>
array(
['notSame'] => 'The two given tokens do not match'
)
正如你可能假设,该错误显示出来,即使 “PASS1” 和 “PASS2” 包含相同的字符串(它基本上是一个密码确认表单)。
我不能使用Zend_Form或addValidator()(不要问),所以我必须使用这个语法,这就是为什么我认为它不起作用。我指的是array(array('Identical', true, 'token' => 'pass1'))
。我甚至试过array(array('Identical', true, array('token' => 'pass1')))
,得到相同的错误。我似乎无法理解这些数组在哪里设置。
建议,更正或“halp!”。
我不知道你在哪里得到了来自例子,但我看说明书,现在[和它的不存在(http://framework.zend.com/manual /en/zend.validate.set.html)。我**可以**使用Zend_Validate_ *;我没有说我不能。我只是不能使用addValidator()的[(更简单)语法)(http://www.wjgilmore.com/blog/entry/validating_identical_passwords_with_the_zend_framework)。我之前使用过Zend_Filter_Input,但不是“完全相同”的。 – nevvermind 2011-05-03 07:20:41
好吧,我已经在ZF的源代码中玩了一下,它似乎验证了我的“pass2”输入值(比如“xxx”)**为“pass1”**,而不是**“pass1” 。如果我在“pass2”文本输入中键入“pass1”,它将起作用。 ZF如何知道令牌的值是输入的名称而不是实际值?代码位于Zend_Validate_Identical :: isValid()中。 – nevvermind 2011-05-03 09:00:01