2

I'm trying to extend a form and add an upload file field from within a module, I can see the file field just fine, but it's empty when I submit the form, the enctype is set.

  $form['#attributes'] = array(
    'enctype' => "multipart/form-data"
  );

  $form['file_upload'] = array(
    '#type' => 'file',
    '#title' => 'Attach Image'
  );

custom form submit hook:

$form['#submit'][] = 'user_images_handler';

is being called, but when I dump the form, the file field is empty, and when I try to access it, it's empty as well.

2 Answers 2

2

File uploads are special in that the 'submitted' (uploaded) data does not end up in the form, but needs to be processed separately (uploading is not really a part of form submission but a separate transmission process).

See the docs for file_save_upload(), and as an example, see how it is used on form submission usage from within the upload module.

Basically, you just try to save the upload by calling file_save_upload() with the name of the upload field (and some other arguments) and check the result of this try.

0

Hmm, I tried that and it didn't work...it still says the upload field is empty. I have a debugging print statement at the submit function but it doesn't print so I don't think it is even getting to the submit function.

Where are you suppose to put the file_save_upload() call?

Note, my form is named mmil_upload_form ( $form_state ) and the submit function is named function mmil_upload_form_submit ( $form, &$form_state )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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