Same name and namespace in other branches
- 5.x developer/hooks/core.php \hook_forms()
- 7.x modules/system/system.api.php \hook_forms()
Map form_ids to builder functions.
This hook allows modules to build multiple forms from a single form "factory" function but each form will have a different form id for submission, validation, theming or alteration by other modules.
The callback arguments will be passed as parameters to the function. Callers of drupal_get_form() are also able to pass in parameters. These will be appended after those specified by hook_forms().
See node_forms() for an actual example of how multiple forms share a common building function.
Parameters
$form_id: The unique string identifying the desired form.
$args: An array containing the original arguments provided to drupal_get_form().
Return value
An array keyed by form id with callbacks and optional, callback arguments.
Related topics
4 functions implement hook_forms()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- node_forms in modules/
node/ node.module - Implementation of hook_forms(). All node forms share the same form handler
- search_forms in modules/
search/ search.module - trigger_forms in modules/
trigger/ trigger.module - Implementation of hook_forms(). We reuse code by using the same assignment form definition for each node-op combination.
- user_forms in modules/
user/ user.module - Implementation of hook_forms().
1 invocation of hook_forms()
- drupal_retrieve_form in includes/
form.inc - Retrieves the structured array that defines a given form.
File
- developer/
hooks/ core.php, line 837 - These are the hooks that are invoked by the Drupal core.
Code
function hook_forms($form_id, $args) {
$forms['mymodule_first_form'] = array(
'callback' => 'mymodule_form_builder',
'callback arguments' => array(
'some parameter',
),
);
$forms['mymodule_second_form'] = array(
'callback' => 'mymodule_form_builder',
);
return $forms;
}