ZF-11707: Disabling input type="file" in a form causes zend_file_transfer_adapter_http::isValid to enter workaround block of code and returning false (not validating)

Description

In Zend_File_Transfer_Adapter_Http::isValid() there is a block with comment: "// Workaround for a PHP error returning empty $_FILES when form data exceeds php settings" This workaround is executed not only when form data exceeds php settings, but also when you submit a form with 1 disabled file element and other non file element.

The condition for entering workarund should also check if sttings were exceeded.

This bug is somewhat connected to: #ZF-10279.

After submitting a form with a single file element which is not required and disabled, and other, non file elements, $_FILES is an empty array. Having empty array in $_FILES, Zend_File_Transfer_Adapter_Http::_prepareFiles() produces empty array in Zend_File_Transfer_Adapter_Http::_files.

Since $_POST is not empty (because of other, non file form elements), condition: "if (empty($this->_files) && ($content > 0)) {" is true in Zend_File_Transfer_Adapter_Http::isValid(), and isValid returns false.

Comments

Zend_File does not know about Zend_Form_Element. When Zend_Form says that there is an file element which has to be validated Zend_File tries to validate it (as it is called by Zend_Form).

My expectation is that validations should NOT BE PROCESSED/DONE for disabled elements. Therefor I don't see this as failure from Zend_File but from Zend_Form which should not try to validate an disabled element.

Please give an example of your problem. How do you disable a special input type?

Fixed with GH-388

Is this problem really solved in 1.x version?

I'm trying to submit form with disabled file field & still get errors using latest (1.11.11) ZF version.

My Code:


$form = new Zend_Form();
        
$form->setMethod('POST')
  ->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
        
$title = new Zend_Form_Element_Text('title');
$title->setLabel('Title')
  ->setRequired();
$form->addElement($title);
        
$file = new Zend_Form_Element_File('file');
$file->setLabel('File')
  ->setAttrib('disabled', true)
  ->setValueDisabled(true);
$form->addElement($file);
        
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Submit');
$form->addElement($submit);

When trying to validate form I get error: 'fileUploadErrorIniSize' => string 'File 'file' exceeds the defined ini size'

Fix needs to be backported from ZF2

You can use this simple workaround before calling isValid():


if(!isset($_FILES[$form_element_name])) {
    $_FILES[$form_element_name] = array(
                  'name' => '',
                  'type' => '',
                  'tmp_name' => '',
                  'error' => 4,
                  'size' => 0);
}

this is not work for me the post data $this->getRequest()->getPost() return: array 'exam' => array 'exam_id' => string '' (length=0) 'exam_dates_id' => string '' (length=0) 'disability' => string '0' (length=1) 'save' => string 'Save and continue' (length=17) 'MAX_FILE_SIZE' => string '8388608' (length=7) but var_dump($_FILES); return empty !