ZF-5864: Zend_Form_Element_File in sub form: name attribute is not rendered using the array notation

Issue Type: Bug Created: 2009-02-23T08:36:17.000+0000 Last Updated: 2009-08-09T14:08:12.000+0000 Status: Resolved Fix version(s): - 1.9.0 (31/Jul/09)

Reporter: G Cohen (untitled4) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

Related issues: - ZF-5835



When creating a file element in a sub form the name attribute should use the array notation in this form: sub_form[element_name] but this work.

I have the following two elements in a sub form: $image_src = new Zend_Form_Element_File ('image_src'); $this->addElement($image_src);

$image_alt = new Zend_Form_Element_Text('image_alt'); $this->addElement($image_alt);

The elements as rendered in the sub form look like this:


Posted by Matthew Weier O'Phinney (matthew) on 2009-02-23T09:00:56.000+0000

Assigning to Thomas. Thomas, make sure the decorators are using getFullyQualifiedName().

Posted by Thomas Weidner (thomas) on 2009-02-23T13:42:44.000+0000

@G.: I just verified but I can't get your results. When I name the file element "image_src" the rendered element is also named "image_src" and not "image".

Related to the sub_form notation: This is nothing which can be done for file elements.

The problem arises when you use Sub-Sub-Forms, or deeper nesting, or when you use multifiles with Sub-Forms. PHP then brakes the Sub-Form notation into something unreadable. For example a file within a 3 level nested Sub-Form would be named "subform3[subform2][subform1][subform0][image_src]". But the resulting $_FILES array is Array ([subform3] => Array ([name] => Array ([subform2] => Array ([subform1] => Array ([subform0] => Array ([image_src] => filename)))) As the resulting name is broken in multiple sub arrays the upload is broken.

This is within PHP itself a not defined behaviour. And this behaviour is different depending on the used PHP version. Therefor we change the naming of file elements to match the accepted PHP naming notation.

With the actual PHP releases there is no known solution to this problem as it's simply not defined.

This is not a bug, this is wished behaviour and I think it's also documented.

Posted by G Cohen (untitled4) on 2009-02-23T15:02:55.000+0000

Thank you for responding so quickly.

The first "issue" is my own fault as I was trying to simplify the code for this report and got it wrong. I do get image_src as the element name.

The issue I was addressing is that I am expecting the file element to be name "image_form['image_src]" (if my sub form is named image_form) and for it to be part of the sub form array when I request the form data when I process it. This is (simplified again) what I am expecting:

$form_data = $this->_request->getPost(); $image_data = $form_data['image_form'];

but $image_form does not contain the data (file name) from the file element, so what I have to do ($main_form is my main form): $image_form = $main_form->getSubForm('image_form'); $image_data = $image_form->getValues();

I only have one sub form to main form (I'm not so ambitious as to have sub forms nested in sub forms).

Obviously, it's not a big deal and the workaround doesn't require a lot of work, but I still think it is a bug as I was expecting it to behave in the same way as other sub form elements but it and I think the idea of array notation is very useful, but not if the file element is missing from it.

If it's impossible for the file element to be added to the array notation in sub forms then I think the documentation (…) should be changed to reflect that.

Thanks again for your time.


Posted by Thomas Weidner (thomas) on 2009-06-11T08:52:49.000+0000

Fixed with r16002 (documentation).

Have you found an issue?

See the Overview section for more details.


© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.