PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject_FormBuilder » Bug #5664

subform file field

Details

Submitted2005-10-12 02:40 UTC
Fromsdc at spiretech dot com
Assignedjustinpatrin
StatusClosed
PackageDB_DataObject_FormBuilder
PHP Version4.3.4
OSRH Linux
Roadmaps(Not assigned)

Comments

[2005-10-12 02:40 UTC] sdc at spiretech dot com

Description:
------------
File upload fields in a linked subform (one that is hidden and revealed by picking --New Value--) don't seem to pass the uploaded file into the $_FILES array.

I think this is because the form created doesn't have the 'multipart/form-data' attribute set when the file upload field is present (starting out hidden) on a sub-form.

I don't know if this would be a problem with FormBuilder, or HTML_QuickForm.

My file upload logic works properly on the child table properly by itself. it doesn't work when part of a sub-form.

Test script:
---------------
Create two tables, one that contains some text and another that contains some image data.
Table foo
-id (int)
-name (text)
-picture (int, links to image->id)

Table images
id (int)
icon (text, stores image path)

Setup DB_DataObjects for above.

in table images, put together preGenerateForm to replace the text input field with a file input field.

overload the insert function in table images and do a $this->debug($_FILES) in it.

View table images in a form by itself. View the outputted HTML source and you will see that the <form> tag contains a 'multipart/form-data' with it.

View table foo and pick --New Value-- to show the subform with the file upload field on it. View HTML source and see that the <form> tag does not have the 'multipart/form-data' attribute set. When submitting the form, you will see that the $_FILES array is also empty.

Expected result:
----------------
Form with subfields containing input types of file should have 'multipart/form-data' attribute set so that file data will be received properly.

Actual result:
--------------
Outputted HTML source does not have 'multipart/form-data' attribute set.

[2005-10-12 03:30 UTC] sdc at spiretech dot com

how do I set the content type? I'm not setting it anywhere- it seems to automagically get set down in the guts of the code somewhere. I've only found one occurence of it, and thats inside the source for HTML_Quickform.

[2005-10-12 05:02 UTC] sdc at spiretech dot com

thanks for the quick response and new code. unfortunately, the conditional you added doesn't seem to be getting triggered.
I added some debugging code in your new function to see what was going on. It gets to the loop and iterates through all the elements, but it's not triggering the true state to set the element type.

[2005-10-12 06:10 UTC] sdc at spiretech dot com

I'm creating it like this:
//..
$el = & HTML_QuickForm::createElement('file', $fb->getFieldName('icon'), 'Icon');

//...
$this->fb_preDefElements['icon'] = $el;

[2005-10-13 05:21 UTC] sdc at spiretech dot com

Any more word on this?
to further answer your question, yes it should be on the form.. unless the substitution happens after that section of code you wrote is called. I'm setting it up in preGenerateForm like I documented in the previous post. It shows up in the generated html. the only bit that doesn't happen is the 'multipart/form-data' getting set properly.

[2005-10-13 06:23 UTC] sdc at spiretech dot com

sorry, our posts crossed. got the new version from cvs and it's now setting the multipart on the form correctly.
but I may have another problem - my $_FILES array is still empty.
in my insert I'm doing a
$this->debug($_FILES);
and it's printing empty.

[2005-10-13 06:36 UTC] sdc at spiretech dot com

now I see it. for some reason the form method is set to get, not post. seems like it was post before..

[2005-10-13 07:40 UTC] sdc at spiretech dot com

I was forcing it to get elsewhere in my code. corrected that and it works now.
An interesting but not-so-obvious side effect of using the file field on a subform is that it gets renamed. so when you extract it out of the $_FILES array later you need to make sure you are using the correct key (the renamed form field).