form_get_cache

  1. drupal
    1. 6
    2. 8
    3. 7
Versions
6 – 7 form_get_cache($form_build_id, &$form_state)

Fetch a form from cache.

Related topics

▾ 2 functions call form_get_cache()

ajax_get_form in includes/ajax.inc
Get a form submitted via #ajax during an Ajax callback.
drupal_build_form in includes/form.inc
Build and process a form based on a form id.

Code

includes/form.inc, line 486

<?php
function form_get_cache($form_build_id, &$form_state) {
  if ($cached = cache_get('form_' . $form_build_id, 'cache_form')) {
    $form = $cached->data;

    global $user;
    if ((isset($form['#cache_token']) && drupal_valid_token($form['#cache_token'])) || (!isset($form['#cache_token']) && !$user->uid)) {
      if ($cached = cache_get('form_state_' . $form_build_id, 'cache_form')) {
        // Re-populate $form_state for subsequent rebuilds.
        $form_state = $cached->data + $form_state;

        // If the original form is contained in include files, load the files.
        // @see form_load_include()
        $form_state['build_info'] += array('files' => array());
        foreach ($form_state['build_info']['files'] as $file) {
          if (is_array($file)) {
            $file += array(
              'type' => 'inc',
              'name' => $file['module'],
            );
            module_load_include($file['type'], $file['module'], $file['name']);
          }
          elseif (file_exists($file)) {
            require_once DRUPAL_ROOT . '/' . $file;
          }
        }
      }
      return $form;
    }
  }
}
?>