ZF-10262: Zend_Form_Decorator_File when used in subform as array not rendered properly
Description
I have a form which utilize Zend_Form_Element_File like this:
class Forms_Attachment extends Zend_Form
{
function init()
{
$this->addElement(
'file',
'myFile',
array(
'label' => 'Attachment'
)
);
}
}
The attachment form is utilized as a sub form
class Forms_Products_Delivery extends Zend_Form
{
protected $elementDecorators = array(
'viewHelper',
array('label', array('tag' => 'p'))
);
protected $fileDecorators = array(
'file',
array('label', array('tag' => 'p'))
);
protected $hiddenDecorators = array(
'viewHelper'
);
protected $subFormDecorators = array(
'formElements',
'fieldset'
);
function init()
{
$attachmentForm = new Forms_Attachment();
$attachmentForm->setIsArray(true);
$attachmentForm->setElementDecorators($this->elementDecorators);
$attachmentForm->setElementDecorators($this->fileDecorators, array('myFile'));
$attachmentForm->setDecorators($this->subFormDecorators);
$this->addSubForm($attachmentForm, 'attachments');
}
}
when rendering form get this result
Product Attachments
Attachment
Title
Description
while I need to have
Product Attachments
Attachment
Title
Description
The difference is that the file fields is not properly rendered using the Zend_Form_Decorator_File, however I can't use 'viewRender' decorator as it throws an error. If I use "file" decorator in conjunction with 'viewRenderer' I simply get two instances of the file field one incorrect and one correct.
Comments
Posted by Thomas Weidner (thomas) on 2010-08-06T08:42:33.000+0000
Did you see http://framework.zend.com/manual/en/… and http://framework.zend.com/issues/browse/ZF-5864.
According to manual file elements can not be rendered as sub-form.
{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}
I think this issue can actually be fixed as non-issue.
Posted by Thomas Weidner (thomas) on 2010-08-06T08:43:05.000+0000
Closing as non-issue.. see the documentation
Posted by Thomas Weidner (thomas) on 2010-11-22T11:47:04.000+0000
Correct fix version as it has been deleted unintentionally by another user