ZF-4102: Zend_Form_Element_File in subform
Description
Zend_Form_Element_File does not deliver file name of uploaded file when form element is inside a subform.
As far as i was able to find out. Zend_File_Adapter_Http stores the uploaded files internal in _files[SUBFORM-NAME__ELEMENT-NAME], but on Zend_Form_Element_File isValid() calles $this->setValue($adapter->getFileName($this->getName())); providing the elements name. The adapter now returns null because it cant find an entry in _files for the elements name.
public function getFileName($file) { $file = (string) $file; if (!array_key_exists($file, $this->_files)) { return null; }
$directory = $this->getDestination($file);
return $directory . DIRECTORY_SEPARATOR . $this->_files[$file]['name'];
}
Having the element in the form instead of a subform works fine.
Comments
Posted by Dragos Ionita (fusion5) on 2008-08-28T07:26:49.000+0000
Yep, I'm having the same problem, to recreate it simply add a Zend_Form_Element_File in a subform and when you submit the file you get the error:
Notice: Undefined index: name in C:\workspace\ZendFramework\library\Zend\File\Transfer\Adapter\Abstract.php on line 745
Posted by Loic Bistuer (loic.bistuer) on 2008-09-13T05:11:26.000+0000
I second that.
I reckon it'll be pretty hard to fix without modifying Zend_Form itself. I stumbled on the same issue while implementing my own Form_Element_File class.
The problem being that at the time of validation Zend_Form_Element(s) aren't aware of their fully qualified name. This is generally not an issue for other elements since they don't have to dig themselves into the $_POST array, but in this case the element needs to analyze the $_FILE array by itself.
Posted by Thomas Weidner (thomas) on 2008-09-25T15:07:09.000+0000
Fixed with r11520