开发者

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?


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)


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜