I am using hook_nodeapi() to display the node's information in an email when the user clicks on the "Save" button. I tried writing code for the "presave" operation, but that didn't work the way I wanted. I tried using a query to pull out the node data, but the data wasn't in the database until after the "postsave" operation.

Which $op is the right one for me? I tried 'insert' as well, and that didn't work.

  • 1
    Should work with insert. What Drupal version? Can you post the code?
    – Michael D
    May 7, 2012 at 6:27
  • I am using Drupal 6, and no, update and insert don't work as well. When I try update it does the same thing as presave, and when I try insert nothing happens at all. It seems that clicking on the save button doesn't call the insert switch. May 7, 2012 at 17:32
  • $op is "insert" only on node creation, $op is "update" only on already created node-save. This might help: api.drupal.org/api/examples/… I can't help further if you don't show your code.
    – Michael D
    May 9, 2012 at 4:13

1 Answer 1


Thanks to a bit of a to-and-fro in your other questions (this one and this one) I think I know what the problem is.

Without going into great detail, the content module (CCK) also implements hook_nodeapi(), in order to commit the field data to the database. What's currently happening is that the hooks implemented by your module are being called before the hooks for the content module, which means at the time your implementation of hook_nodeapi() is run, CCK's implementation has not run; hence the data not being found in the database.

In my experience unless you explicitly set the weight of certain modules, they're ordered by name alphabetically, and as your module name begins with 'a' it does make sense that this would happen.

To get around it you just need to increase the 'weight' of your module in the system. Have a look at How to update a module's weight for more information but essentially you want to run a query like this against your database:

db_query("UPDATE {system} SET weight = 100 WHERE name = 'yourmodulename'");

After that clear Drupal's caches and you should see things starting to behave a bit differently.

  • Wow, I would have never have guessed something like this. But I just tried what you said and nothing happened. I used phpAdmin to do a search for the ckk module in the system table and it wasn't there! (My own module was there.) It doesn't seem to have a weight and I guess that's why I can't 'under-weigh' it. How can I fix this? May 10, 2012 at 17:38
  • The machine name for the CCK module is 'content', you should be able to find it in the table under that
    – Clive
    May 10, 2012 at 17:41
  • Yeah, I was just about to edit my comment above, I found the cck. Its weight is 0 and mine is 100, so what you are describing sounds like it should work.... but it didn't. I am still not getting the updated data. And I did clear the cache too. May 10, 2012 at 17:50
  • Hmm that really is bizarre; have you definitely cleared Drupal's caches since you updated the table? If not do that, if you have, try running it again a couple of times. I know that's almost as poor advice as "try restarting the computer" but I'm really out of ideas!
    – Clive
    May 10, 2012 at 17:54
  • Actually, something weird just happened. I thought it wasn't working, but there has been some change. Most of the info which gets emailed out is old data and hasn't been updated. One piece, however, the node->title (see how I pass $node to alert_message_mail_send()) does get updated in the email. Does that help? NOTE: I can't really be sure that this always worked, I don't think I ever tested the node title. May 10, 2012 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.