function fp_get_form
Search API
7.x render.inc | fp_get_form($form_id, $params = array()) |
6.x render.inc | fp_get_form($form_id, $params = array()) |
4.x forms.inc | fp_get_form($form_id, $params = array()) |
5.x render.inc | fp_get_form($form_id, $params = array()) |
This function gets the form array, where the callback is the same as form_id. It will also look for modules which may want to alter the form, using hook_form_alter, and go ahead and apply that.
It will also reorder the elements by weight.
2 calls to fp_get_form()
- fp_render_form in includes/
render.inc - Render the form array from the callback to the screen, and set the form to save itself in our default submit handler. Valid form_types are: "system_settings" => values automatically saved to variables table. "normal" or BLANK…
- system_handle_form_submit in modules/
system/ system.module - Intercepts form submissions from forms built with the form API.
File
- includes/
render.inc, line 165
Code
function fp_get_form($form_id, $params = array()) {
$form = call_user_func_array($form_id, $params);
// Add in the default submit_handlers and validate_handlers, if not all ready set.
if (!isset($form ["#submit_handlers"])) {
$form ["#submit_handlers"] = array($form_id . "_submit");
}
if (!isset($form ["#validate_handlers"])) {
$form ["#validate_handlers"] = array($form_id . "_validate");
}
$modules = modules_implement_hook("form_alter");
foreach ($modules as $module) {
call_user_func_array($module . '_form_alter', array(&$form, $form_id));
}
// Okay, now the fun part. Re-order the elements by weight. Lighter weights
// should float to the top. Elements w/o a weight listed are assumed to have a weight of 0.
// Unfortunately we cannot use uasort, as it re-orders our indexes when weights are identical.
// The first the I want to do is find out, what are the defined weights in this form, if any.
$defined_weights = array();
foreach ($form as $element) {
if (!isset($element ["weight"])) {
$element ["weight"] = 0;
}
$weight = (int) $element ["weight"];
if (!in_array($weight, $defined_weights)) {
$defined_weights [] = $weight;
}
}
// Okay, now sort our weights.
sort($defined_weights);
// Before we get to assigning weights, we need to make sure
// that none of our form elements have a name which might cause us trouble.
// Namely, no element can be named "submit" (like a button) because it will
// interfere with our javascript functions.
$form2 = array();
foreach ($form as $key => $element) {
$name = $key;
if ($name == "submit") {
$name = "btn_submit";
}
$form2 [$name] = $element;
}
$form = $form2;
// Okay, now go through the weights and create a new form in THAT order.
$new_form = array();
foreach ($defined_weights as $dw) {
foreach ($form as $key => $element) {
if (!isset($element ["weight"])) {
$element ["weight"] = 0;
}
$weight = (int) $element ["weight"];
if ($weight == $dw) {
$new_form [$key] = $element;
}
}
}
// Okay, we should now be good to go!
return $new_form;
}