I have built a couple of forms in drupal 6.x and drupal 7.x, where we collect some info and give them the ability to upload their resume. Some of the fields are required and some are not. When I choose to upload a file and select the file I want to upload and hit submit ... the form validation kicks in and highlights the missing required fields, but at the same time, it is clearing the name of the file that I chose to submit. So, if the user thinks that I have already selected the file to upload and just corrects the error in the form and submits again, since the resume is not a required field, the form gets submitted without the file that was chosen before.

Is there any way to make the page remember the file chosen in the previous step?

Thank you,


shabana.navas’s picture

Have you used '#default_value' for that field? Ex.:

$form['textfield'] = array(
  '#type' => 'textfield',
  '#title' => t('My field'),
  '#default_value' => isset($form_state['values']['textfield']) ? $form_state['values']['textfield'] : ' ',

Shabana Navas
Software Developer
Acro Media
Skype: super.shaba

imranweb’s picture

You can't "pre-fill" the contents of a file upload field for security reasons.

If you use Drupal CCK field for file, it put a upload button next to the file element.
You need to upload the file at temporary location, if in fail condition.


bssr’s picture

I am using the file field from the form API ... so, in order to upload the file to a temporary location. I need to write a custom form validation function, correct?

imranweb’s picture

No, i guess Drupal handles automatically.