By SteveTurnbull-1 on
I want a really simple upload because I need to import some data to populate a table. So I have this:
function product_import_form() {
$form['#attributes'] = array('enctype' => "multipart/form-data") ;
$form['upload'] = array(
'#type' => 'file'
) ;
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Import'),
'#weight' => 10
);
return $form ;
}
which successfully displays the form. I find a file and click 'import'. And I go to this validation routine:
function product_import_form_validate($form_id, $form_values) {
drupal_set_message(hackory_var($form_values)) ;
}
The "hackory_var" is my own routine to return a "var_dump" as a string, and the result is this:
Array
(
[upload] =>
[op] => Import
[submit] => Import
[form_token] => 96fd82d5062217094045e57118b94109
[form_id] => product_import_form
)
As you can see 'upload' is blank, doesn't matter what file I specify.
Any idea why this isn't working? Have I missed something obvious?
Steve
Comments
For completeness, here's the
For completeness, here's the HTML that's generated:
The way I got it to work was
The way I got it to work was in the hook_validate I used file_check_upload(); Inside the function you would put 'upload'. Here is an example for something I did.
In my hook validate
I hope this helps you out.
The trouble was, I didn't believe it...
Thanks.
The problem was that I couldn't believe the way to access the file information was to use file_check_upload with the field name used in the form. I was being too clever for my own good.
I suppose I'm still kind-of going "huh?" but I do have it working now. Thanks for convincing me.
Steve