7

If there are required fields in a form (ie '#required' is set to TRUE), and the user sets a file to be uploaded but not provide all the required fields, validation fails on the required fields and the validation hook does not get called; the specified file does not get uploaded (if that is where the upload code is placed) and the form is refreshed without the previously provided filename wiped out. Is there a way to either upload the file during validation, or reset the filename in the form field, so that the user doesn't have to reselect it again?

thanks

1

I believe using the File_Managed fieldtype will fix your problem. This Drupal FAPI field type uploads the file to a temp directory BEFORE the form is submitted, and so you can access the file during/after validation. You can see an example of it being applied in the "image_example.pages.inc" in the Examples module. Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.