dimirc
dimirc

Reputation: 6625

zend Identical Validator problem when leaving one element empty

I'm using the following code:

$form->addElement('password', 'elementOne');
$form->addElement('password', 'elementTwo', array(
    'validators' => array(
        array('identical', false, array('token' => 'elementOne'))
    )
));

If both texts are different I get an error from the validator, but if I leave the second one empty the validation wont fire. why?

(I dont want to put the fields as required because the user should fill them only if he wants to change the password but he could also leave them empty)

What am I doing wrong? should I put the validator on both elements?

Upvotes: 0

Views: 294

Answers (2)

dimirc
dimirc

Reputation: 6625

The problem was the AllowEmpty flag (when the element is not required this flag is set to true). I set it to false and the validator is now firing as expected.

setAllowEmpty(false)

Upvotes: 1

Mr Coder
Mr Coder

Reputation: 8196

$form->addElement('password', 'elementOne');
$form->addElement('password', 'elementTwo', array(
    'validators' => array(
        array('identical', false, array('token' => $_POST['elementOne']))
    )
));

Upvotes: 0

Related Questions