hook_form_alter() and hook_nodeapi() to alter fields and insert additional data on insert


As mentioned in the comments any extra fields you add to to a node form won't automatically be persisted to the database, the node module only takes care of the fields that it knows about.

Traditionally there are 2 options:

  1. Use CCK instead and add fields to the node that way. Then you don't need to take care of data storage/loading yourself.
  2. Add your own table for data storage using hook_schema(), making sure you have a column for nid (node id). Then in hook_nodeapi() use the insert and update ops to run a db_query() to insert/update the data in that table for the current node.

    Then you just need to load that data back from the DB on to the $node object in the load op of hook_nodeapi(). Your data will then be available at $node->field_name when you have a node object loaded with node_load().

Tags: Drupal 6 / Hooks

Similar questions

hook_nodeapi() argument?
hook_nodeapi() only has four arguments, but the function taxonomy_nodeapi($node, $op, $arg = 0) can have an additional parameter, $arg=0. Why? $node is not passed by reference. Why?
How do I use hook_nodeapi()?
I found an example on the Internet: Transform CCK field to body content. I don't know what the purpose of the following code is. Why should I use it? What's the use of the hook_nodeapi() arguments $a3 and a4? If in the case of a view operation, I set the $a3 to true or 1, will the body only effect on the node teaser? Am I right?
Why isn't code for $op == 'presave' being executed in hook_nodeapi?
I want the administrator users can publish nodes of the story content type; the other roles can unpublish. The following is the code I am using, but it doesn't work. I unchecked the box "published", which is in the "story" content type. I am using echo 'test' above on the if ($op....), the page outputs "test." When I put the echo 'test' into if bod...
hook_nodeapi() is great on nodes, but what can I use on non-node pages?
I'm building a module that needs to do stuff wherever the user is browsing, but I used hook_nodeapi(), which is ordinarily great but it is not coping with non-node pages (such as views, and user profile pages). Does anyone have any idea on which hook should I run in such circumstances?
Run hook_nodeapi("pre save") but only on inserts, not on updates
For hook_nodeapi(), I want it to run on "presave," but only on inserts, not on updates. How can I do that?
hook_nodeapi called multiple times with op='update'
I am using the media_mover module. I added some debug code to media_mover's hook_nodeapi: When the user edits and saves a node, hook_nodeapi is getting called twice with $op='update'. Anyone know why this might be? If media_mover calls node_save during the process of saving the updated node, might that cause hook_nodeapi to be called multiple times...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.