function form_load_include

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

module_load_include()

Related topics

4 calls to form_load_include()
form_test_load_include_custom in drupal/core/modules/system/tests/modules/form_test/form_test.module
Menu callback for testing custom form includes.
locale_translate_import_form in drupal/core/modules/locale/locale.bulk.inc
Form constructor for the translation import screen.
user_admin_settings in drupal/core/modules/user/user.admin.inc
Form builder; Configure user settings for this site.
user_multiple_cancel_confirm in drupal/core/modules/user/user.module

File

drupal/core/includes/form.inc, line 609
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;
}