function drupal_get_form

Returns a renderable form array for a given form ID.

This function should be used instead of drupal_build_form() when $form_state is not needed (i.e., when initially rendering the form) and is often used as a menu callback.

Parameters

\Drupal\Core\Form\FormInterface|string $form_arg: A form object to use to build the form, or the unique string identifying the desired form. If $form_arg is a string and 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 constructor function. Examples may be found in node_forms(), and search_forms().

...: Any additional arguments are passed on to the functions called by drupal_get_form(), including the unique form constructor function. For example, the node_edit form requires that a node object is passed in here when it is called. These are available to implementations of hook_form_alter() and hook_form_FORM_ID_alter() as the array $form_state['build_info']['args'].

Return value

The form array.

See also

drupal_build_form()

Related topics

28 calls to drupal_get_form()
ActionListController::render in drupal/core/modules/action/lib/Drupal/action/ActionListController.php
Implements \Drupal\Core\Entity\EntityListControllerInterface::render().
ajax_test_dialog in drupal/core/modules/system/tests/modules/ajax_test/ajax_test.module
Menu callback: Renders a form elements and links with #ajax['dialog'].
authorize.php in drupal/core/authorize.php
Administrative script for running authorized file operations.
BlockListController::render in drupal/core/modules/block/lib/Drupal/block/BlockListController.php
Overrides \Drupal\Core\Entity\EntityListController::render().
book_outline in drupal/core/modules/book/book.pages.inc
Page callback: Shows the outline form for a single node.

... See full list

26 string references to 'drupal_get_form'
aggregator_menu in drupal/core/modules/aggregator/aggregator.module
Implements hook_menu().
ajax_forms_test_menu in drupal/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
Implements hook_menu().
batch_test_menu in drupal/core/modules/system/tests/modules/batch_test/batch_test.module
Implements hook_menu().
book_menu in drupal/core/modules/book/book.module
Implements hook_menu().
config_menu in drupal/core/modules/config/config.module
Implements hook_menu().

... See full list

File

drupal/core/includes/form.inc, line 162
Functions for form and batch generation and processing.

Code

function drupal_get_form($form_arg) {
  $form_state = array();
  $args = func_get_args();

  // Remove $form_arg from the arguments.
  array_shift($args);
  $form_state['build_info']['args'] = $args;
  $form_id = _drupal_form_id($form_arg, $form_state);
  return drupal_build_form($form_id, $form_state);
}