function hook_form

7.x node.api.php hook_form($node, &$form_state)
6.x node.php hook_form(&$node, $form_state)

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.

$form_state: The form state array. Changes made to this variable will have no effect.

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

87 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.

block_add_block_form in drupal-6.x/modules/block/block.admin.inc
Menu callback: display the custom block addition form.
block_admin_display_form in drupal-6.x/modules/block/block.admin.inc
Generate main blocks administration form.
block_box_form in drupal-6.x/modules/block/block.module
Define the custom block form.
blog_form in drupal-6.x/modules/blog/blog.module
Implementation of hook_form().
book_outline_form in drupal-6.x/modules/book/book.pages.inc
Build the form to handle all book outline operations via the outline tab.

... See full list

1 invocation of hook_form()
node_form in drupal-6.x/modules/node/node.pages.inc
Generate the node add/edit form array.

File

documentation-6.x/developer/hooks/node.php, line 245
These hooks are defined by node modules, modules that define a new kind of node.

Code

function hook_form(&$node, $form_state) {
  $type = node_get_types('type', $node);

  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
  );

  $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);

  $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;
}