My post deals with a slight problem that I'm having with inserting. I am expanding the event module to include a location field. The event module utilizes nodeapi. When I put all of the fields in and hit preview, it looks fine, which tells me that during the node instance of preview the $node->location is set, but it never inserts it into the database, so it does not actually come up when users view it. My event table has the following fields
int(10) start
int(10) end
int(10) tz //timezone
int(10) nid
varchar(20) location
Here's a quick rundown of the important code:
//First I have a form textarea for the location
function event_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
...
case 'form post':
$form = '';
if (variable_get('event_nodeapi_'. $node->type, 'never') != 'never') {
global $user;
$form .= form_textarea(t('Location:'), 'location', $node->location, 30, 20, '', NULL, FALSE);
}
}
return $form;
...
//Then I have my insert function.
case 'insert':
if (variable_get('event_nodeapi_'. $node->type, 'never') != 'never') {
$fields = array('nid', 'start', 'end', 'location');
db_query('INSERT INTO {event} (nid, start, end, tz, location) VALUES (%d, %d, %d, %d, %s)', $node->nid, $node->start, $node->end, $node->tz, $node->location);
}
event_set_range();
break;