ZF-11801: formFile ViewHelper renders id /name attribute not correct when in subform

Issue Type: Bug Created: 2011-10-06T20:18:29.000+0000 Last Updated: 2011-10-22T09:06:01.000+0000 Status: Resolved Fix version(s): Reporter: Sascha Hübner (xzed) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

  • Zend_Form_Decorator_File
  • Zend_Form_Element_File

Related issues: Attachments:


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.

<pre class="highlight">
$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' => $preview_image

<pre class="highlight">
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.


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) {

     * this will set the right id (with filedset-id prefix just like the Label Deorator's "for"-attribute-value) and name attribute (array notation with fieldset prefix"

     $this->getDecorator('File')->setOptions(array('name' => $this->getFullyQualifiedName(),'id' => $this->getId() ));

   return parent::render($this->getView());


rendered output: Example:

Test Bild - Bitte wählen Sie ein entsprechendes Bild: .jpg .png .gif / min. 800px*800px

Posted 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.

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.