drupal_get_form

includes/form.inc, line 48

Versions
4.7
drupal_get_form($form_id, &$form, $callback = NULL)
5 – 7
drupal_get_form($form_id)

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 definition, then rendering the requested step for display.

Parameters

$form_id The unique string identifying the desired form. If a function with that name exists, it is called to build the form array. Modules that need to generate the same form (or very similar forms) using different $form_ids can implement hook_forms(), which maps different $form_id values to the proper form building function. Examples may be found in node_forms(), search_forms(), and user_forms().

... Any additional arguments needed by the form building function.

Return value

The rendered form.

Related topics

▾ 38 functions call drupal_get_form()

book_admin in modules/book/book.module
Menu callback; displays the book administration page.
comment_admin in modules/comment/comment.module
Menu callback; present an administrative comment listing.
comment_delete in modules/comment/comment.module
Menu callback; delete a comment.
comment_form_box in modules/comment/comment.module
comment_render in modules/comment/comment.module
Renders comment(s).
contact_site_page in modules/contact/contact.module
Site-wide contact page
contact_user_page in modules/contact/contact.module
Personal contact page.
forum_form_main in modules/forum/forum.module
install_change_settings in ./install.php
Configure and rewrite settings.php.
install_select_locale in ./install.php
Find all .po files for the current profile and allow admin to select which to use.
install_select_profile in ./install.php
Find all .profile files and allow admin to select which to install.
locale_admin_import in modules/locale/locale.module
Page handler for the translation import screen
locale_admin_manage in modules/locale/locale.module
Page handler for the language management screen.
locale_admin_string_delete_page in modules/locale/locale.module
String deletion confirmation page.
locale_string_search in modules/locale/locale.module
Page handler for the string search.
node_add in modules/node/node.module
Present a node submission form or a set of links to such forms.
node_admin_content in modules/node/node.module
Menu callback: content administration.
node_admin_search in modules/node/node.module
node_page_edit in modules/node/node.module
Menu callback; presents the node editing form, or redirects to delete confirmation.
node_revision_delete in modules/node/node.module
Delete the revision with specified revision number. A "delete revision" nodeapi event is invoked when a revision is deleted.
node_revision_revert in modules/node/node.module
Revert to the revision with the specified revision number. A node and nodeapi "update" event is triggered (via the node_save() call) when a revision is reverted.
phptemplate_page in themes/engines/phptemplate/phptemplate.engine
Prepare the values passed to the theme_page function to be passed into a pluggable template engine. Uses the arg() function to generate a series of page template files suggestions based on the current path. If none are found, the default page.tpl.php...
poll_view in modules/poll/poll.module
Implementation of hook_view().
search_block in modules/search/search.module
Implementation of hook_block().
search_view in modules/search/search.module
Menu callback; presents the search form and/or search results.
taxonomy_admin_term_edit in modules/taxonomy/taxonomy.module
Page to edit a vocabulary term.
taxonomy_admin_vocabulary_edit in modules/taxonomy/taxonomy.module
Page to edit a vocabulary.
theme_poll_results in modules/poll/poll.module
update_selection_page in ./update.php
user_admin in modules/user/user.module
user_admin_access_add in modules/user/user.module
Menu callback: add an access rule
user_admin_access_check in modules/user/user.module
Menu callback: check an access rule
user_admin_access_edit in modules/user/user.module
Menu callback: edit an access rule
user_block in modules/user/user.module
Implementation of hook_block().
user_edit in modules/user/user.module
watchdog_overview in modules/watchdog/watchdog.module
Menu callback; displays a listing of log messages.
_locale_admin_export_screen in includes/locale.inc
User interface for the translation export screen
_locale_admin_manage_add_screen in includes/locale.inc
User interface for the language addition screen.

Code

<?php
function drupal_get_form($form_id) {
  // In multi-step form scenarios, the incoming $_POST values are not
  // necessarily intended for the current form. We need to build
  // a copy of the previously built form for validation and processing,
  // then go on to the one that was requested if everything works.

  $form_build_id = md5(mt_rand());
  if (isset($_POST['form_build_id']) && isset($_SESSION['form'][$_POST['form_build_id']]['args']) && $_POST['form_id'] == $form_id) {
    // There's a previously stored multi-step form. We should handle
    // IT first.
    $stored = TRUE;
    $args = $_SESSION['form'][$_POST['form_build_id']]['args'];
    $form = call_user_func_array('drupal_retrieve_form', $args);
    $form['#build_id'] = $_POST['form_build_id'];
  }
  else {
    // We're coming in fresh; build things as they would be. If the
    // form's #multistep flag is set, store the build parameters so
    // the same form can be reconstituted for validation.
    $args = func_get_args();
    $form = call_user_func_array('drupal_retrieve_form', $args);
    if (isset($form['#multistep']) && $form['#multistep']) {
      // Clean up old multistep form session data.
      _drupal_clean_form_sessions();
      $_SESSION['form'][$form_build_id] = array('timestamp' => time(), 'args' => $args);
      $form['#build_id'] = $form_build_id;
    }
    $stored = FALSE;
  }

  // Process the form, submit it, and store any errors if necessary.
  drupal_process_form($args[0], $form);

  if ($stored && !form_get_errors()) {
    // If it's a stored form and there were no errors, we processed the
    // stored form successfully. Now we need to build the form that was
    // actually requested. We always pass in the current $_POST values
    // to the builder function, as values from one stage of a multistep
    // form can determine how subsequent steps are displayed.
    $args = func_get_args();
    $args[] = $_POST;
    $form = call_user_func_array('drupal_retrieve_form', $args);
    unset($_SESSION['form'][$_POST['form_build_id']]);
    if (isset($form['#multistep']) && $form['#multistep']) {
      $_SESSION['form'][$form_build_id] = array('timestamp' => time(), 'args' => $args);
      $form['#build_id'] = $form_build_id;
    }
    drupal_prepare_form($args[0], $form);
  }

  return drupal_render_form($args[0], $form);
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.