ZF-11801: formFile ViewHelper renders id /name attribute not correct when in subform
Description
when using a Zend_Form_Element_File - element inside of a fieldset, the fieldset prefix is not added to the name and id of the rendered file input tag.
$preview_image = new Zend_Form_SubForm();
$preview_image->setLegend('Preview Image');
$test_file = new Zend_Form_Element_File('test_file');
$test_file->setLabel('Test Label');
$preview_image->addElement($test_file);
$this->addSubForms(array(
'preview_image' => $preview_image
));
Preview Image
Test Label
The id and name attribute of the file input should be "preview_image-test_file" just like the label's for attribute value. And of course the name should be the FullyQualifiedName "preview_image[test_file]". At least the ViewHelpers in all other Form Elements do behave that way.
If I set the 'ViewHleper' as additional Decorator, the output of the ViewHelper (uses 'formFile' in this case) is right. But since I have to use the 'File' Decorator also ( I don't understand why ), the output of this one is wrong.
Comments
Posted by Sascha Hübner (xzed) on 2011-10-09T20:18:03.000+0000
I've found a workaround for this bug: - build an own File Element Class:
class My_Form_File extends Zend_Form_Element_File { // public function render(Zend_View_Interface $view = null) {
}
rendered output: Example:
Test BildPosted by Frank Brückner (frosch) on 2011-10-10T07:48:41.000+0000
Code tags added.
Posted by Thomas Weidner (thomas) on 2011-10-22T09:05:42.000+0000
From the manual: {quote} Note: File elements in Subforms When you use file elements in subforms you must set unique names. For example, if you name a file element in subform1 "file", you must give any file element in subform2 a different name. If there are 2 file elements with the same name, the second element is not be displayed or submitted. Additionally, file elements are not rendered within the sub-form. So when you add a file element into a subform, then the element will be rendered within the main form. {quote}
This is the reason why the file element is not rendered within the subform "preview_image". The restriction is due to nested file uploads being broken.