1

I would like to automatically save a CCK field which will be determined by the data in the $node object. Using node_save in this instance will cause an error so I need a way to simply insert the additional field into the database.

One obvious way is to simply call db_insert but I'm not sure that this is the best way to do this since most of the information in this table is automatically generated and I'd like to leave that up to Drupal if I can.

What is that standard approach in this case?

Thanks!

0

1 Answer 1

3

You could probably do this in hook_node_presave(), e.g.:

function MYMODULE_node_presave($node) {
  // Get a value made up of other submitted fields, e.g.
  $computed_val = $node->field_first[$node->language][0]['value'] + $node->field_second[$node->language][0]['value'];

  // Assign that value to the other field
  $node->field_computed_field[$node->language][0]['value'] =  $computed_val;
}
0

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.