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

Display a node editing form.

This is a node-type-specific hook, which is invoked only for the node type being affected. See Node API hooks for more information.

Use hook_form_BASE_FORM_ID_alter(), with base form ID 'node_form', to alter node forms for all node types.

This hook, implemented by node modules, is called to retrieve the form that is displayed to create or edit a node. This form is displayed at path node/add/[node type] or node/[node ID]/edit.

The submit and preview buttons, administrative and display controls, and sections added by other modules (such as path settings, menu settings, comment settings, and fields managed by the Field UI module) are displayed automatically by the node module. This hook just needs to return the node title and form editing fields specific to the node type.

Parameters

$node: The node being added or edited.

$form_state: The form state array.

Return value

An array containing the title and any custom form elements to be displayed in the node editing form.

Related topics

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

aggregator_admin_form in modules/aggregator/aggregator.admin.inc
Form constructor for the aggregator system settings.
aggregator_page_category_form in modules/aggregator/aggregator.pages.inc
Page callback: Displays a form containing items aggregated in a category.
aggregator_page_source_form in modules/aggregator/aggregator.pages.inc
Page callback: Displays a form with all items captured from a feed.
ajax_forms_test_ajax_commands_form in modules/simpletest/tests/ajax_forms_test.module
Form to display the Ajax Commands.
ajax_forms_test_lazy_load_form in modules/simpletest/tests/ajax_forms_test.module
Form builder: Builds a form that triggers a simple AJAX callback.

... See full list

1 invocation of hook_form()
field_attach_form in modules/field/field.attach.inc
Add form elements for all fields for an entity to a form structure.

File

modules/node/node.api.php, line 1123
Hooks provided by the Node module.

Code

function hook_form($node, &$form_state) {
  $type = node_type_get_type($node);
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#default_value' => !empty($node->title) ? $node->title : '',
    '#required' => TRUE,
    '#weight' => -5,
  );
  $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('Choose an option.'),
  );
  return $form;
}