I have the code below, and I want to update the fields on my node using hook_nodeapi()
. How do I set the fields on insert?
/*
* Implements hook_form_alter().
*/
function feature_contact_form_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'contact_form_node_form') {
$form['field_user_agent']['#type'] = 'hidden';
$form['field_ip_address']['#type'] = 'hidden';
$form['buttons']['submit']['#weight'] = 1;
}
}
/*
* Implements hook_nodeapi().
*/
function feature_contact_form_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($node->type == 'contact_form') {
if ($op == 'insert') {
function getRealIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
$ipaddress = getRealIpAddr($ip);
$node->field_user_agent = array($ipaddress);
$node->field_ip_address = array($_SERVER['HTTP_USER_AGENT']);
}
}
}
$form['test']
in your form, you'll be able to access it at$node->test
in the insert op, but Drupal doesn't know to do anything with that data so it won't write it to the db or load it back up when the node is reloaded. I might've misunderstood what you mean though, sorry if that's the case