ZF-9944: Zend_Form_Element_File loses breakChainOnFailure option if NotEmpty validator is not supplied
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.
Comments
Posted by Christian Albrecht (alab) on 2010-06-03T10:14:34.000+0000
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?
Posted by Elnur Abdurrakhimov (elnur) on 2010-06-03T11:54:48.000+0000
This is the simplified version of my form which is enough to reproduce the bug:
Try to upload a file which is larger than the size limit of this form (5M) but is smaller {{than post_max_size}} (in my case it's 8M).
Posted by Christian Albrecht (alab) on 2010-06-03T12:56:12.000+0000
Assigning to Thomas and updating Components
Posted by Thomas Weidner (thomas) on 2010-06-04T13:20:12.000+0000
New feature implemented with r22372