I'm creating a custom node module and have run into a bit of a problem. In my submit handler, is there a way to store info to the node being created? I need to transfer some information from the submit handler to my hook_insert function. However my submit handler only has $form and $form_state as parameters, no $node. What is the best way to go about doing this?

Comments

mscdex’s picture

No suggestions?

shariff’s picture

I don't really understand what you're trying to do.
If you have a form within the module where you defined your content type this should call node_save() which will call hook_insert() automatically if the node is new. Or you can use hook_update() if the node has been edited.

Ciao

mscdex’s picture

I have some custom (not an existing form field) data generated in the submit handler for my custom node type's form. I need to use this generated information in mymodule_insert() when I save to the database. If a FormsAPI submit function signature provided for a $node parameter, I could simply just do $node->somedata = "foo"; and then access $node->somedata in mymodule_insert(). But since I do not have such direct access to the node in a FormsAPI submit handler, I cannot figure how to transfer this information to make it accessible when I go to insert the node into the database.

Here's an example:

function mynode_submit($form, &$form_state) {
     $somedata = "GeneratedData"; // where to assign this value? $form_state['values']['somedata']?
}

function mynode_insert($node) {
     $data = $node->somedata;

     ...
}

I hope that makes more sense.

noizee’s picture

I'm not above doing something like this:

$somedata = nil;

function mynode_submit($form, &$form_state) {
     global $somedata;
     $somedata = "GeneratedData"; // where to assign this value? $form_state['values']['somedata']?
}

function mynode_insert($node) {
     global $somedata;
     $data = $somedata;

     ...
}

The life expectency of $somedata is exactly one page. It gets killed every page, so any 'global's are just widely scoped page scoped variables.