Definition

hook_form(&$node, &$param)
contributions/docs/developer/hooks/node.php, line 107

Description

Display a node editing form.

This hook, implemented by node modules, is called to retrieve the form that is displayed when one attempts to "create" an item. This form is displayed at the URI http://www.yoursite.com/?q=node/add/nodetype.

The "Title" field, submit and preview buttons, and administrative accoutrements are displayed automatically by node.module. This hook needs to return only the body text area, taxonomy controls, and fields specific to the node type.

For a detailed usage example, see node_example.module.

Parameters

&$node The node being added or edited.

&$param The hook can set this variable to an associative array of attributes to add to the enclosing \<form\> tag.

Return value

A string containing HTML defining form elements to be displayed in the node edit form.

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

function hook_form(&$node, &$param) {
  if (function_exists('taxonomy_node_form')) {
    $output = implode('', taxonomy_node_form('example', $node));
  }

  $output .= form_textfield(t('Custom field'), 'field1', $node->field1, 60,
    127);
  $output .= form_select(t('Select box'), 'selectbox', $node->selectbox,
    array (1 => 'Option A', 2 => 'Option B', 3 => 'Option C'),
    t('Please choose an option.'));

  return $output;
}