create nodes with attached files using drupal_execute
Hello, I'm new to the forms API and hoping for some advice. I am creating a multistep form in 5.3. The form uses drupal_execute to generate new CCK nodes. The basic form is working, but I cannot figure out how to make drupal_execute attach files to the new nodes as it creates them. I would like to simply pass a form value to the CCK node form (through drupal_execute) along with the other necessary fields. E.g. something along the lines of $values['file']['field_object_file_upload'][0] = $form_values['my_form_file_upload_field']; Solutions involving either upload module or a CCK file field would be fine. Does anyone have advice? (I hope this is an appropriate question for the "development" list. Based on the descriptions at lists.drupal.org that seems to be the case; if not, please let me know where I should post it.) Thanks for your help!
Have you added this line to your form? $form['#attributes']['enctype'] = 'multipart/form-data'; On Nov 14, 2007, at 5:18 PM, Isaac Simon Hodes wrote:
Hello, I’m new to the forms API and hoping for some advice. I am creating a multistep form in 5.3. The form uses drupal_execute to generate new CCK nodes. The basic form is working, but I cannot figure out how to make drupal_execute attach files to the new nodes as it creates them.
I would like to simply pass a form value to the CCK node form (through drupal_execute) along with the other necessary fields. E.g. something along the lines of
$values['file']['field_object_file_upload'][0] = $form_values [‘my_form_file_upload_field’];
Solutions involving either upload module or a CCK file field would be fine.
Does anyone have advice? (I hope this is an appropriate question for the “development” list. Based on the descriptions at lists.drupal.org that seems to be the case; if not, please let me know where I should post it.) Thanks for your help!
Consider using the Upload API module, http://drupal.org/project/upapi. It provides a form element type for a file upload, making it relatively easy to add file fields to nodes and other Drupal forms. It is not exposed via CCK, but hopefully will be in the future. For now, you have to use hook_form or hook_form_alter. It also has some support for previews. That is, hit the preview button on the node form and you'll see files that haven't yet been submitted. As far as I know neither the upload module or the CCK fields support this. -Dave On Wed, 14 Nov 2007 17:18:44 -0500, "Isaac Simon Hodes" <ISimonHodes@jwa.org> said:
Hello, I'm new to the forms API and hoping for some advice. I am creating a multistep form in 5.3. The form uses drupal_execute to generate new CCK nodes. The basic form is working, but I cannot figure out how to make drupal_execute attach files to the new nodes as it creates them.
I would like to simply pass a form value to the CCK node form (through drupal_execute) along with the other necessary fields. E.g. something along the lines of
$values['file']['field_object_file_upload'][0] = $form_values['my_form_file_upload_field'];
Solutions involving either upload module or a CCK file field would be fine.
Does anyone have advice? (I hope this is an appropriate question for the "development" list. Based on the descriptions at lists.drupal.org that seems to be the case; if not, please let me know where I should post it.) Thanks for your help!
The form uses drupal_execute to generate new CCK nodes. $values['file']['field_object_file_upload'][0] =
You have a problem here -- files are stored in FILES not in POST by PHP hence Form API does not deal with files at all -- form_values is a derived from POST.You need to handle uploads separately. Also, just populating FILES is not enough if I remember correctly PHP has an internal structure so an upload is not easily emulatable. You yourself will need to put the file on disk, save the entry into {files}... If you figure this out -- maybe with more help from the list -- please post to http://drupal.org/node/191154 -- this seems to be a popular question these days.
participants (4)
-
Darren Oh -
David Cohen -
Isaac Simon Hodes -
Karoly Negyesi