I would like to use user-submitted data from one form field and add it to anther field, then submit the form to create a node that has my custom data. I'm having a hard time doing this. Any help is appreciated.

  • create your form for create node and change value before saving node. Jul 22, 2011 at 15:41

1 Answer 1


This is what the node api hooks are good for.

From the docs:

The node passed validation and is about to be saved. Modules may use this to make changes to the node before it is saved to the database.

You don't specify D6 or D7

In D6

hook_nodeapi() $op == 'presave'

In D7


You can modify values in your implementations of these hooks and they will be saved.


If you need the NID you have to use hook_node_insert, but you will have to save to the DB directly.

  • D7. The problem I'm running into is this: I need to use the node's nid to populate a node reference field (referencing a different entity with the same id #). However, it appears that the nid field isn't populated until the node is saved. Perhaps I need to reload the node once it is saved? Jul 22, 2011 at 16:23
  • Edited, with solution, but trying to keep IDs in sync is a very tricky way to go. If one gets created but the other doesn't your site will break. Jul 22, 2011 at 16:40
  • Hmm - adding node_save($node) to hook_node_insert seems to cause a PDO exception - duplicate entry Jul 22, 2011 at 16:52
  • but you will have to save to the DB directly... Jul 22, 2011 at 17:57
  • 1
    OK, not with node_save() but rather db_insert() I'll give this a try thanks for your help. Jul 23, 2011 at 1:47

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.