Community Documentation

hook_form

5 node.php hook_form(&$node, $form_values)
6 node.php hook_form(&$node, $form_state)
7 node.api.php hook_form($node, &$form_state)
8 node.api.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.

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

▾ 42 functions implement hook_form()

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
confirm_form in modules/system.module
drupal_get_form in includes/form.inc
Processes a form array and produces the HTML output of a form. If there is input in the $_POST['edit'] variable, this function will attempt to validate it, using drupal_validate_form(), and then submit the form using drupal_submit_form().
drupal_submit_form in includes/form.inc
drupal_validate_form in includes/form.inc
fileupload_form in developer/examples/fileupload.module
Implementation of hook_form().
filter_admin_format_form in modules/filter.module
Generate a filter format form.
filter_form in modules/filter.module
Generate a selector for choosing a format in a form.
forum_form in modules/forum.module
Implementation of hook_form().
locale_admin_manage_delete_form in modules/locale.module
User interface for the language deletion confirmation screen.
menu_edit_item_form in modules/menu.module
Present the menu item editing form.
menu_edit_menu_form in modules/menu.module
Menu callback; handle the adding/editing of a new menu.
menu_item_delete_form in modules/menu.module
Menu callback; delete a single custom item.
multipage_form_example_form in developer/examples/multipage_form_example.module
Implementation of hook_form() for multipage_form_example. We don't set ANY #required attributes here - we leave that up to multipage_form_example_pre_render().
node_example_form in developer/examples/node_example.module
Implementation of hook_form().
node_filter_form in modules/node.module
Return form for node administration filters.
node_form in modules/node.module
Generate the node editing form.
page_form in modules/page.module
Implementation of hook_form().
path_form in modules/path.module
Return a form for editing or creating an individual URL alias.
poll_form in modules/poll.module
Implementation of hook_form().
profile_field_form in modules/profile.module
Menu callback: Generate a form to add/edit a user profile field.
search_form in modules/search.module
Render a search form.
story_form in modules/story.module
Implementation of hook_form().
system_settings_form in modules/system.module
system_theme_select_form in modules/system.module
Returns a fieldset containing the theme select form.
taxonomy_form in modules/taxonomy.module
Generate a form element for selecting terms from a vocabulary.
theme_archive_browse_form in modules/archive.module
Form theme function; displays the archive date navigation form inline.
theme_form in includes/form.inc
Format a form.
theme_multipage_form_example_node_form in developer/examples/multipage_form_example.module
theme_node_filter_form in modules/node.module
Theme node administration filter form.
theme_node_form in modules/node.module
theme_search_block_form in modules/search.module
Theme the block search form.
theme_search_theme_form in modules/search.module
Theme the theme search form.
theme_system_theme_select_form in modules/system.module
user_edit_form in modules/user.module
_locale_string_seek_form in includes/locale.inc
User interface for the string search screen
_upload_form in modules/upload.module
_user_admin_access_form in modules/user.module

File

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

Code

<?php
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;
}
?>
Login or register to post comments