Confirm same password with Zend_Filter_Input
ZF 1.11.3 here.
$validators = array(
'pass1' => array('presence' => 'required'),
'pass2' => array(array('Identical', true, 'token' => 'pass1'))
),
$inpu开发者_高级运维t = new Zend_Filter_Input(array(), $validators, $this->_request->getParams());
if (!$input->isValid()) {
var_dump($input->getMessages());
}
Using the code above, I get (firephp formatted, actually):
['pass2'] =>
array(
['notSame'] => 'The two given tokens do not match'
)
As you've might presume, that error shows up even if "pass1" and "pass2" contain the same string (it's basically a password confirmation form).
I cannot use Zend_Form or addValidator() (don't ask), so I must joggle with this syntax, which is why I think it doesn't work. I'm referring to array(array('Identical', true, 'token' => 'pass1'))
. I've even tried array(array('Identical', true, array('token' => 'pass1')))
, getting the same error. I don't seem to understand where those arrays are to be set.
Suggestions, corrections or "halp!".
If you can't use Zend_Valiate_*
you can't use Zend_Filter_Input
because Zend_Filter_Input
will try to create instances of the validators given in the array.
Furthermore I think your syntax is wrong. Look at this example from the manual:
$validators = array(
'password' => array(
'Identical',
'fields' => array('password1', 'password2')
)
);
If Zend_Filter_Input were to use the context, it would validate comparing to the value of some_input_name
, not to a string like some_input_name
. And because I don't use Zend_Form, it can't use context.
Zend_Filter_Input not working with context but through of the Zend_Form_Element you can use context.
http://framework.zend.com/issues/browse/ZF-10673
精彩评论