Issues

ZF-12189: Zend_File_Transfer_Adapter_Abstract wrong validation when file is not send

Description

Hello,

I have a Zend_Form that has an Zend_Form_Element_File element, the element is not required. But when I submit the form when the Zend_Form_Element_File is hidden by JS or CSS (display:none) the file is not send as part of the $_FILES array. This is as expected. But Zend_File_Transfer_Adapter_Abstract still tries to validate the file, which is impossible because it's not sent and because it was set as not required it should not be checked. Somehow it's not looking at the ignoreNoFile (which is set to true for this not required file) option of the file.

The problem is that the isValid() function uses _getFiles() to check the files. _getFiles() is returning an empty array if the expected file is not submitted, and because of that the validation returns false. No error message is being set though.

The following patch is working for me, but I didn't test it very well yet. The patch was made in the isValid function inside Zend_File_Transfer_Adapter_Abstract.

Changed:


$check = $this->_getFiles($files, false, true);
if (empty($check)) {
    return false;
}

To:


$check = $this->_getFiles($files, false, true);
if (empty($check)) {
    if ($this->_options['ignoreNoFile']) {
        return true;
    }
    return false;
}

Comments

I am new to Zend's issue tracker, but is it normal that issues remain untouched for several weeks? Can I expect a follow up on this issue?

Hi Nick, at the moment there are two main tasks:

  • working on the 1.12 release
  • working on the new shiny version 2 of the Zend Framework

I'll look at this issue, but you can also help with a patch and some unit tests for this issue. (You must send the CLA to Zend!)

(Another reason why there was no or only a late feedback: the component maintainer Thomas works no longer for the Zend Framework project.)

The patch proposed by Nick is also working for me. But I can't tell if this will cause a side effect on some other parts of the component.