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.
1 Answer
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
hook_nodeapi() $op == 'presave'
You can modify values in your implementations of these hooks and they will be saved.
edit
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
-
-
1OK, not with node_save() but rather db_insert() I'll give this a try thanks for your help. Jul 23, 2011 at 1:47