You are here

function ajax_comments_form_get_cache in AJAX Comments 6

Fetch a form from cache.

1 call to ajax_comments_form_get_cache()
ajax_comments_js in ./ajax_comments.pages.inc
AHAH callback.

File

./ajax_comments.pages.inc, line 115
AJAX comments form handling and callbacks.

Code

function ajax_comments_form_get_cache($form_build_id, &$form_state) {
  global $user;
  if ($cached = ajax_comments_cache_get('form_' . $form_build_id, 'cache_form')) {
    $form = $cached->data;
    if (isset($form['#cache_token']) && drupal_valid_token($form['#cache_token']) || !isset($form['#cache_token']) && !$user->uid) {
      if ($cached = ajax_comments_cache_get('storage_' . $form_build_id, 'cache_form')) {
        $form_state['storage'] = $cached->data;
      }

      // Rewind form values.
      $elements = element_children($form);
      if (!empty($elements)) {
        foreach ($elements as $element) {
          if (in_array($form[$element]['#type'], array(
            'textfield',
            'textarea',
            'select',
            'checkbox',
            'radio',
            'checkboxes',
            'radios',
          ))) {
            unset($form[$element]['#value']);
          }
        }
      }
      return $form;
    }
  }
}