1 form.inc | form_load_include(&$form_state, $type, $module, $name = NULL) |
Ensures an include file is loaded whenever the form is processed.
Example:
// Load node.admin.inc from Node module.
form_load_include($form_state, 'inc', 'node', 'node.admin');
Use this function instead of module_load_include() from inside a form constructor or any form processing logic as it ensures that the include file is loaded whenever the form is processed. In contrast to using module_load_include() directly, form_load_include() makes sure the include file is correctly loaded also if the form is cached.
Parameters
$form_state: The current state of the form.
$type: The include file's type (file extension).
$module: The module to which the include file belongs.
$name: (optional) The base file name (without the $type extension). If omitted, $module is used; i.e., resulting in "$module.$type" by default.
Return value
The filepath of the loaded include file, or FALSE if the include file was: not found or has been loaded already.
See also
Related topics
File
- core/
includes/ form.inc, line 660 - Functions for form and batch generation and processing.
Code
function form_load_include(&$form_state, $type, $module, $name = NULL) {
if (!isset($name)) {
$name = $module;
}
if (!isset($form_state['build_info']['files']["$module:$name.$type"])) {
// Only add successfully included files to the form state.
if ($result = module_load_include($type, $module, $name)) {
$form_state['build_info']['files']["$module:$name.$type"] = array(
'type' => $type,
'module' => $module,
'name' => $name,
);
return $result;
}
}
return FALSE;
}