Search code examples
validationzend-frameworkpassword-confirmation

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'))
),

$input = 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!".


Solution

  • 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