Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.10.5
-
Fix Version/s: 1.10.6
-
Component/s: Zend_Form, Zend_Validate, Zend_Validate_File
-
Labels:None
Description
If I create a file upload form element with several validators, setting $breakChainOnFailure for each of them, the chain doesn't break and several error messages are shown.
I've spent hours to find the reason and I've found it. This is the faulty part of Zend_Form_Element_File::isValid()'s body:
if (!$this->isRequired()) { $adapter->setOptions(array('ignoreNoFile' => true), $this->getName()); } else { $adapter->setOptions(array('ignoreNoFile' => false), $this->getName()); if ($this->autoInsertNotEmptyValidator() and !$this->getValidator('NotEmpty')) { $validators = $this->getValidators(); $notEmpty = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true); array_unshift($validators, $notEmpty); $this->setValidators($validators); } }
As you can see, this code checks if the element is set to be required and if it is and NotEmpty validator is not supplied, it gets all already set validators, adds NotEmpty to them, and sets them back. Unfortunately is loses $breakChainOnFailure option of all those previously set validators during this process.
The temporary workaround to this bug is to explicitly add NotEmpty validator to the element.
Sorry i cannot reproduce this in current trunk and 1.10 release branch with the following setup:
Could you provide a simple Testcase that does fail for you?