drupal_retrieve_form
6/includes/form.inc, line 319
- 6
drupal_retrieve_form($form_id, &$form_state)
- 5
drupal_retrieve_form($form_id)
Retrieves the structured array that defines a given form.
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 constructor function.
$form_state
A keyed array containing the current state of the form.
...
Any additional arguments needed by the unique form constructor
function. Generally, these are any arguments passed into the
drupal_get_form() or drupal_execute() functions after the first
argument. If a module implements hook_forms(), it can examine
these additional arguments and conditionally return different
builder functions as well.
Related topics
- Form generation
- Functions to enable the processing and display of HTML forms.
Code
<?php
function drupal_retrieve_form($form_id, &$form_state) {
static $forms;
$args = func_get_args();
$saved_args = $args;
array_shift($args);
if (isset($form_state)) {
array_shift($args);
}
if (!function_exists($form_id)) {
if (!isset($forms) || !isset($forms[$form_id])) {
$forms = module_invoke_all('forms', $form_id, $args);
}
$form_definition = $forms[$form_id];
if (isset($form_definition['callback arguments'])) {
$args = array_merge($form_definition['callback arguments'], $args);
}
if (isset($form_definition['callback'])) {
$callback = $form_definition['callback'];
}
}
array_unshift($args, NULL);
$args[0] = &$form_state;
$form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);
$form['#parameters'] = $saved_args;
return $form;
}
?>