Same name and namespace in other branches
  1. 4.6.x developer/hooks/node.php \hook_form()
  2. 5.x developer/hooks/node.php \hook_form()
  3. 6.x developer/hooks/node.php \hook_form()
  4. 7.x modules/node/node.api.php \hook_form()

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/edit" an item. This form is displayed at the URI http://www.example.com/?q=node/<add|edit>/nodetype.

Parameters

&$node: The node being added or edited.

Return value

An array containing the form elements to be displayed in the node edit form.

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

For a detailed usage example, see node_example.module.

Related topics

39 functions implement hook_form()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

archive_browse_form in modules/archive.module
Generate a form that retrieves archives for a certain date.
block_box_form in modules/block.module
blog_form in modules/blog.module
Implementation of hook_form().
book_form in modules/book.module
Implementation of hook_form().
comment_form in modules/comment.module

... See full list

File

developer/hooks/node.php, line 182
These hooks are defined by node modules, modules that define a new kind of node.

Code

function hook_form(&$node) {
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#required' => TRUE,
  );
  $form['body'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#rows' => 20,
    '#required' => TRUE,
  );
  $form['field1'] = array(
    '#type' => 'textfield',
    '#title' => t('Custom field'),
    '#default_value' => $node->field1,
    '#maxlength' => 127,
  );
  $form['selectbox'] = array(
    '#type' => 'select',
    '#title' => t('Select box'),
    '#default_value' => $node->selectbox,
    '#options' => array(
      1 => 'Option A',
      2 => 'Option B',
      3 => 'Option C',
    ),
    '#description' => t('Please choose an option.'),
  );
  return $form;
}