7.x form.inc form_load_include(&$form_state, $type, $module, $name = NULL)

Ensures an include file is loaded whenever the form is processed.


  // 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.


$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

1 call to form_load_include()
form_test_load_include_custom in modules/simpletest/tests/form_test.module
Menu callback for testing custom form includes.


includes/form.inc, line 648
Functions for form and batch generation and processing.


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;


aaron.r.carlton’s picture

I wonder why this function expects the include file to come from a module. My use case is trying to add an include file to a theme settings form.

vomitHatSteve’s picture

This has been replaced by FormState::loadInclude()