Drupal 6 hook_form_FORM_ID_alter add upload file field

I am trying to expand the form and add a file upload field from the module, I can see that the file field is just fine, but it is empty, when I submit the form the type is set to enctype.

  $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 called, but when I delete the form the file field is empty and when I try to access it it is also empty.

+2


source to share


2 answers


File uploads are special in that the "submitted" (uploaded) data is not included in the form, but needs to be processed separately (uploading is not part of the form submission, but a separate submission process).

See the docs forfile_save_upload()

, and as an example, see how this is used when using the form submission from the load module .



Basically, you are just trying to save the load by calling file_save_upload()

with the load field name (and some other arguments) and check the result of that attempt.

+2


source


Hmm I tried this and it didn't work ... it still says the upload field is empty. I have a debug print instruction in the send function, but it doesn't print, so I don't think it even ends up in the send function.

Where can you put the file_save_upload () call?



Please note, my form has a name mmil_upload_form ( $form_state )

and the submit function is calledfunction mmil_upload_form_submit ( $form, &$form_state )

0


source







All Articles