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.

$form_values: The form values array.

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

▾ 61 functions implement hook_form()

block_box_form in modules/block/block.module
blog_form in modules/blog/blog.module
Implementation of hook_form().
book_form in modules/book/book.module
Implementation of hook_form().
color_scheme_form in modules/color/color.module
Form callback. Returns the configuration form.
comment_form in modules/comment/comment.module
confirm_form in modules/system/system.module
Output a confirmation form
drupal_get_form in includes/form.inc
Retrieves a form from a builder function, passes it on for processing, and renders the form or redirects to its destination as appropriate. In multi-step form scenarios, it handles properly processing the values using the previous step's form…
drupal_prepare_form in includes/form.inc
Prepares a structured form array by adding required elements, executing any hook_form_alter functions, and optionally inserting a validation token to prevent tampering.
drupal_process_form in includes/form.inc
This function is the heart of form API. The form gets built, validated and in appropriate cases, submitted.
drupal_redirect_form in includes/form.inc
Redirect the user to a URL after a form has been processed.
drupal_render_form in includes/form.inc
Renders a structured form array into themed HTML.
drupal_retrieve_form in includes/form.inc
Retrieves the structured array that defines a given form.
drupal_submit_form in includes/form.inc
Processes user-submitted form data from a global variable using the submit functions defined in a structured form array.
drupal_validate_form in includes/form.inc
Validates user-submitted form data from a global variable using the validate functions defined in a structured form array.
fileupload_form in developer/examples/fileupload.module
Implementation of hook_form().
filter_admin_format_form in modules/filter/filter.module
Generate a filter format form.
filter_form in modules/filter/filter.module
Generate a selector for choosing a format in a form.
forum_form in modules/forum/forum.module
Implementation of hook_form().
install_select_locale_form in ./install.php
install_select_profile_form in ./install.php
install_settings_form in ./install.php
Form API array definition for install_settings.
locale_add_language_form in includes/locale.inc
locale_admin_manage_delete_form in modules/locale/locale.module
User interface for the language deletion confirmation screen.
locale_custom_language_form in includes/locale.inc
locale_string_delete_form in modules/locale/locale.module
User interface for the string deletion confirmation screen.
menu_edit_item_form in modules/menu/menu.module
Present the menu item editing form.
menu_edit_menu_form in modules/menu/menu.module
Menu callback; handle the adding/editing of a new menu.
menu_item_delete_form in modules/menu/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_content_form in modules/node/node.module
Implementation of hook_form().
node_example_form in developer/examples/node_example.module
Implementation of hook_form().
node_filter_form in modules/node/node.module
Return form for node administration filters.
node_form in modules/node/node.module
Generate the node add/edit form array.
node_type_form in modules/node/content_types.inc
Generates the node type editing form.
path_form in modules/path/path.module
Return a form for editing or creating an individual URL alias.
poll_cancel_form in modules/poll/poll.module
poll_form in modules/poll/poll.module
Implementation of hook_form().
profile_field_form in modules/profile/profile.module
Menu callback: Generate a form to add/edit a user profile field.
search_form in modules/search/search.module
Render a search form.
system_modules_confirm_form in modules/system/system.module
system_modules_uninstall_confirm_form in modules/system/system.module
Confirm uninstall of selected modules.
system_settings_form in modules/system/system.module
Add default buttons to a form and set its prefix
system_theme_select_form in modules/system/system.module
Returns a fieldset containing the theme select form.
taxonomy_form in modules/taxonomy/taxonomy.module
Generate a form element for selecting terms from a vocabulary.
theme_color_scheme_form in modules/color/color.module
Theme color form.
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/node.module
Theme node administration filter form.
theme_node_form in modules/node/node.module
theme_search_block_form in modules/search/search.module
Theme the block search form.
theme_search_theme_form in modules/search/search.module
Theme the theme search form.
theme_system_theme_select_form in modules/system/system.module
theme_user_filter_form in modules/user/user.module
Theme user administration filter form.
update_script_selection_form in ./update.php
user_admin_access_form in modules/user/user.module
user_edit_form in modules/user/user.module
user_filter_form in modules/user/user.module
Return form for user administration filters.
_locale_export_pot_form in includes/locale.inc
_locale_export_po_form in includes/locale.inc
_locale_string_seek_form in includes/locale.inc
User interface for the string search screen
_upload_form in modules/upload/upload.module

File

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

Code

<?php
function hook_form(&$node, $form_values) {
  $type = node_get_types('type', $node);

  $form['title'] = array(
    '#type' => 'textfield', 
    '#title' => check_plain($type->title_label), 
    '#required' => TRUE,
  );
  $form['body'] = array(
    '#type' => 'textarea', 
    '#title' => check_plain($type->body_label), 
    '#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