# Maintaining states between form submit and node hooks in Drupal 6 — Liran Tal

Insights about Drupal's use of node_save() functions and how the hook_nodeapi() uses a different context than the form submit handler

Canonical: https://lirantal.com/blog/2012-10-26

![Cover artwork for Maintaining states between form submit and node hooks in Drupal 6](/_astro/photo-1468956398224-6d6f66e22c35.BePqp3CW_Zj88Tk.jpg)

With Drupal, it is many times the case where you’d find yourself working with custom forms or alter existing forms through the Form API and end up modifying the submit handler so that you are essentially triggering `node_save()` yourself.

If you find yourself in such scenario where you are also having conditional actions in an implementation of `hook_nodeapi()` then you’ll soon enough realize that there is complete isolation between the `$form` array (or $form\_state for that matter), which is available through the various form hooks, to the node handling hooks.

To give a practical example, imagine a case where upon a field property in the form you would like to handle the node saving that you implement in your custom `hook_nodeapi()` differently. The problem is right there – in your implementation of `hook_nodeapi()` you don’t get the $form nor any access to it, nor is it possible to pass it in any way.

I guess one way to attack the problem would be to glance into `$_POST` and take it from there. Now breadth slowly and forget this was ever an option since we are supposed to do things the ‘right way’ and not the ‘easy way’. Leave your quick-and-dirty work to quick-and-dirty situations (and production environment is not one of them).

Solving the issue though isn’t that hard as it looks – we’ll use the $node object as our temporary storage and simply apply attributes to the object. Because the object is passed by reference to `node_save()` the attribute being used will be available in any of the `hook_nodeapi()` implementations. You also don’t have to worry about the attribute is it’s not going to be persisted to the database.

Taking a practical example at it, assuming you are modifying an existing node, the code may look something like:

```
 function mymodule_node_edit_form_submit($form_id, $form_values) {
 $node = node_load(arg(1));
 $node->title = $form_state['values']['title'];
 // ... rest of your code
 // use an attribute to define some state (or actually pass anything from $form if required)
 $node->is_using_x = TRUE
 node_save($node);
 }
```

Later on in any implementation of `hook_nodeapi()` the `$node` object, passed as reference, will maintain `$node->is_using_x` attribute with whatever payload you’ve set it to.

## More writing

[All writing](/blog)

*   Sep 5, 2026

    ### [Self-Hosting Hermes Agent with Matrix E2EE on Proxmox](/blog/self-host-hermes-agent-matrix-e2ee-proxmox)

*   Aug 2, 2026

    ### [The Practical Second Brain: Building an LLM-Operated Markdown Knowledge Graph](/blog/practical-second-brain-llm-markdown-knowledge-graph)

*   Aug 1, 2026

    ### [Building a Second Brain with LLMs and AI Agents](/blog/building-second-brain-llms-ai-agents)


* * *

Liran Tal is the author of the book [Node.js Secure Coding: Defending Against Command Injection Vulnerabilities](https://www.nodejs-security.com/)

[Start Building Secure Node.js Applications](https://www.nodejs-security.com/)

 [![](/_astro/nodejs-secure-coding-book-3d-style.DiTWpzFs_Z3c7s1.png)](https://www.nodejs-security.com/)
