I have a file upload form
how can I retain this file when there are other validation errors so that the user doesn't have to upload the file again?
I tried this in my validation function but it doesn't work:
function mymodule_someform_validate($form, &$form_state) {
$form_state["values"]["some_field"] = some_value;
}
the $form_state["values"] variable is not available in my form definition function - mymodule_someform($form, &$form_state)
Any ideas?
Just use the
managed_file
type, it'll do it for you:And then in your submit handler:
If the validation fails and the user leaves the form, the file will be automatically deleted a few hours later (as all files in the
file_managed
table withoutFILE_STATUS_PERMANENT
are). If the validation doesn't fail, the submit handler will be run and the file will be marked as permanent in the system.