background image
HomeRecent PostsDrupalSearchTagsRSSContactAboutAccount

Modifying the node form

Eric.London's picture

In certain situations, you might want to modify a node's form and functionality. In this example, I'll explain how to remove the title field from a node's form and add your own title later.

<?php
// using hook_form_alter to remove the node title input field...
function MYMODULE_form_alter($form_id, &$form) {
 
// ...code....
 
if ($form_id == 'MYNODETYPE_node_form' && arg(0)!='admin') {
    unset(
$form['title']);
  }
 
// ...code...
}

// using hook_nodeapi to add the title when the node form is submitted...
function MYMODULE_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
 
// ...code...
 
if ($node->type == 'MYNODETYPE' && $op == 'submit') {
   
// get a list of node types
   
$nodeTypes = node_get_types();
   
// set the node's title
   
$node->title = $nodeTypes[$node->type]->name;
  }
 
// ...code...
}
?>