ZF-2862: Zend_Form validator chain does not keep break on chain when NotEmpty added for required elements
Description
Reproduce code:
$username = new Zend_Form_Element_Text('username');
$username->addValidator('stringLength', true, array(5, 20))
->addValidator('regex', true, array('/^[a-zA-Z0-9_]*$/'))
->addFilter('StringToLower')
->setRequired(true);
$form = new Zend_Form();
$form->addElement($username);
$form->isValid(array('username' => '#'));
echo var_export( $form->getMessages(), 1), "\n\n";
Expected results:
array (
'username' =>
array (
'stringLengthTooShort' => '\'#\' is less than 5 characters long',
),
)
Actual result:
array (
'username' =>
array (
'stringLengthTooShort' => '\'#\' is less than 5 characters long',
'regexNotMatch' => '\'#\' does not match against pattern \'/^[a-zA-Z0-9_]*$/\'',
),
)
Comments
Posted by Matthew Weier O'Phinney (matthew) on 2008-03-11T14:56:53.000+0000
Fixed in trunk and 1.5 release branch. addValidator() was overwriting the zfBreakChainOnFailure flag on the second pass.