Node update: getting the old value
I'm updating a node with nodeapi update, but there's more that I need to do behind the scenes which requires me to know the old value of a field/ Is there a way I could get the old value of a field before it's overw开发者_StackOverflow社区ritten.
Edit
hook_nodeapi()
only acts on the new $node
object, so my earlier answer won't help you. Instead, you'll need to access the node as it gets submitted. To do that, you'll need to register your own submit handler that'll get called when the node form is submitted. It'll give you access to both the current values and the new values:
function test_form_alter(&$form, &$form_state, $form_id) {
if ($form_id === 'contenttype_node_form') { // Replace contenttype
$form['#submit'][] = 'test_submit'; // Add a submit handler
}
}
function test_submit($form, &$form_state) {
// Load the current node object
$node = node_load($form_state['values']['nid']);
// Display the current node object's values
dsm($node);
// Display the submitted values
dsm($form_state['values']);
}
update
is called the $node
object has been updated. You might be more interested in presave
, which checks the node after validation, or validate
, which checks it before validation; both $op
s fire before the new $node
object is saved.
精彩评论