Hi,

I am trying to create a new node type (1st time I have done this) by following the node_example.module. I have been able to have the node created and placed in the database. When the page reloads after I hit submit it goes to a blank page that just has the node title and the node_example_view information. If I click on the title then it displays just the node_example_view. Any ideas on what is going on? Am I not formatting properly.

Comments

nevets’s picture

Without the code to see, did you implement the insert, update and view hooks?

cherrysmooth’s picture

Here is the snippet of my code. I tried going from the example code:

function division_help($section) {
switch ($section) {
case 'admin/modules#description':
// This description is shown in the listing at admin/modules.
return t('League divisions and shortnames.');
case 'node/add#division':
// This description shows up when users click "create content."
return t('Create a division.');
}
}

function division_node_info() {
return array('division' => array('name' => t('division'), 'base' => 'division'));
}

function division_access($op, $node) {
global $user;

if ($op == 'create') {
// Only users with permission to do so may create this node type.
return user_access('create division');
}

// Users who create a node may edit or delete it later, assuming they have the
// necessary permissions.
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own divisions') && ($user->uid == $node->uid)) {
return TRUE;
}
}
}

function division_perm() {
return array('create division', 'edit own divisions');
}

function division_menu($may_cache) {
$items = array();

if ($may_cache) {
$items[] = array('path' => 'node/add/division', 'title' => t('division'),
'access' => user_access('create division'));
}

return $items;
}

function division_form(&$node) {
// We need to define form elements for the node's title and body.
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5
);

// Now we define the form elements specific to our node type.
$form['shortname'] = array(
'#type' => 'textfield',
'#title' => t('Shortname'),
'#default_value' => $node->shortname
);

return $form;
}

function division_validate(&$node) {

}

function division_insert($node) {
db_query("INSERT INTO {sd_divisions} (nid, shortname) VALUES (%d, '%s')", $node->nid, $node->shortname);
}

function division_update($node) {
// if this is a new node or we're adding a new revision,
if ($node->revision) {
division_insert($node);
}
else {
db_query("UPDATE {sd_divisions} SET shortname = '%s' WHERE nid = %d", $node->shortname, $node->nid);
}
}

function division_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'delete revision':
// Notice that we're matching a single revision based on the node's vid.
db_query('DELETE FROM {sd_divisions} WHERE nid = %d', $node->nid);
break;
}
}

function division_delete($node) {
// Notice that we're matching all revision, by using the node's nid.
db_query('DELETE FROM {sd_divisions} WHERE nid = %d', $node->nid);
}

function division_load($node) {
$additions = db_fetch_object(db_query('SELECT shortname FROM {sd_divisions} WHERE nid = %d', $node->nid));
return $additions;
}

function division_view(&$node, $teaser = FALSE, $page = FALSE) {
$node = node_prepare($node, $teaser);
$order_info = theme('division_info', $node);
$node->body .= $order_info;
$node->teaser .= $order_info;
}

function theme_division_info($node) {
$output = '

';
$output .= t('The divisions shortname is %shortname.', array('%shortname' => $node->shortname));
$output .= '

';
return $output;
}