Is it possible to save a node using a multi-step form?

I am creating a Drupal based site that requires a node id to be associated with a separate web service. This web service handles uploading files to a separate server (from one Drupal included).

This creates a problem where, in case I create a new node, the node id is not generated until the form is submitted - this means that I cannot attach files until I save the node and open back to edit it. I would like to remove this step.

Is it possible to create a two step node creation process where the basics of the node will be presented and saved and then the form redirects to the second step where I can attach files?

I would also consider an AJAX-enabled node submission form, but that seems to complicate things further.

Any advice, examples would be appreciated!

+2


source to share


4 answers


you can do this with a multi-step form. see http://pingv.com/blog/ben-jeavons/2009/multi-step-forms-drupal-6-using-variable-functions for a canonical way to do this (besides the code, also check the comments).



you can also do this by adding a second submit handler to the form. first, by default one ( node_form_submit

) saves your node (including the attached file) the standard Drupal path. the second handler can upload the file to a separate server, perform error checking, delete the file from Drupal DB, etc., you can add an extra submit handler to the Drupal 6 form by adding it to the form #submit

property
, either in the form definition or via hook_form_alter

/ hook_form_FORM_ID_alter

.

+4


source


Depending on what exactly you want to do, you can use hook_nodeapi

"insert" in your operation. It runs after the node is successfully created, so the node object will contain the newly assigned null.

NOTE. The API documentation is a bit ambiguous about the "insert" and "update" operations:



"insert": a node is created (inserted into the database).

It looks like it's right in the middle of the process, whereas the node is already created at this point.

+2


source


I think the node_save function can help you.

+1


source


I faced this same problem and did it wrong. I added the hook myself.

http://drupal.org/node/313389

0


source







All Articles