ZF-9944: Zend_Form_Element_File loses breakChainOnFailure option if NotEmpty validator is not supplied

Issue Type: Bug Created: 2010-06-03T07:30:50.000+0000 Last Updated: 2010-06-04T13:20:16.000+0000 Status: Resolved Fix version(s): - 1.10.6 (22/Jun/10)

Reporter: Elnur Abdurrakhimov (elnur) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

  • Zend_Validate
  • Zend_Validate_File

Related issues: Attachments:


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:

<pre class="highlight">
if (!$this->isRequired()) {
    $adapter->setOptions(array('ignoreNoFile' => true), $this->getName());
} else {
    $adapter->setOptions(array('ignoreNoFile' => false), $this->getName());
    if ($this->autoInsertNotEmptyValidator() and
        $validators = $this->getValidators();
        $notEmpty   = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true);
        array_unshift($validators, $notEmpty);

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.


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:

<pre class="highlight">
public function testAction() {                                                                                                                           
         $form = new Zend_Form();
                           array('label' => 'Avatar',
                                 'description' => 'Avatar Description',
                                 'required' => true,
                                 'validators' => array(array('Extension',
                                                                   'messages' => array('fileExtensionFalse' => 'Wrong File Extension'))),
                                                             array('max' => 5242880,
                                                                   'messages' => array('fileSizeTooBig' => 'Filesize too big'))))));

         if ($this->getRequest()->isPost()) {

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:

<pre class="highlight">
class Form_User_Avatar extends Zend_Form
    public function init()
        $this->addElement('file', 'avatar', array(
            'label' => 'Avatar',
            'required' => true,
            'validators' => array(
                array('Extension', true, array(
                array('Size', true, array(
                    'max' => 5242880

        $this->addElement('submit', 'submit');

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

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.