By ilmaestro on
I'm attempting to do file uploads following the fileupload example module. For some reason, when I submit my form, by the time it gets to the form_validate method, the value of my file is wiped out!!! I noticed this only happens when I include the enctype form attribute. If I leave that attribute out, then the file name makes it through just fine, but of course, I can't upload a file without setting the enctype.
What gives?! Any clues as to why my file name is getting wiped out somehow before I even get to the validate method?
Thanks
j
Comments
Insane!!
Yep, this is driving me insane. When I dump the values of $_POST in the validate method, my file field is empty. I remove the enctype, it works. I leave it in, all file inputs do not get through.
What is going on!!!!?!?!
PHP handles file submissions
PHP handles file submissions differently than other post submissions. The details get stored in $_FILES, not $_POST. You have to set the enctype for this to happen.
I recommend you work with the upload api module. If it can't do what you need, contribute to make it better.
Re: dave
Ahh, I see. Wherever PHP sticks the values for file inputs, they weren't getting through since drupal was complaining that I didn't enter a value for that field.
So after a few hours of wasted time, I FINALLY discovered what was causing my file name to get wiped. Having the file field set to required. That's it. And now I see in the documentation that file fields are NOT allowed to have the required attribute set. This seems ridiculous to me. I can do my own validation to ensure a file is uploaded, but I lose the special visual stuff that all my other required fields get.
This is really lame and really disappointing.
For a different application
For a different application I had some success with using a custom "#apparently-required" attribute for certain fields. The form API seemed quite happy to let me add my own custom attribute, and then I themed it to look like a required field, but without the corresponding behaviour/validation...
HTH
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
apparently required
Yea, I'll try something like that.
Thanks
j
a fix
For anyone else who is unhappy with this same issue, there's a discussion of a fix here:
http://drupal.org/node/64984
And a patch is here:
http://drupal.org/files/issues/form-inc-require-file-field.patch
I have no idea why a fix hasn't been committed to the core after seeing many threads over the issue, but... whatever.