diff includes/form.inc @ 9:acef7ccb09b5 6.4

Drupal 6.4
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:32:08 +0100
parents fff6d4c8c043
children 589fb7c02327
line wrap: on
line diff
--- a/includes/form.inc	Tue Dec 23 14:30:28 2008 +0100
+++ b/includes/form.inc	Tue Dec 23 14:32:08 2008 +0100
@@ -1,5 +1,5 @@
 <?php
-// $Id: form.inc,v 1.265.2.7 2008/06/25 09:58:09 dries Exp $
+// $Id: form.inc,v 1.265.2.10 2008/08/13 23:59:12 drumm Exp $
 
 /**
  * @defgroup forms Form builder functions
@@ -100,7 +100,7 @@
       array_unshift($args_temp, $form_id);
 
       $form = call_user_func_array('drupal_retrieve_form', $args_temp);
-      $form_build_id = 'form-'. md5(mt_rand());
+      $form_build_id = 'form-'. md5(uniqid(mt_rand(), true));
       $form['#build_id'] = $form_build_id;
       drupal_prepare_form($form_id, $form, $form_state);
       // Store a copy of the unprocessed form for caching and indicate that it
@@ -216,28 +216,35 @@
 }
 
 /**
- * Fetch a form from cache.
+ * Store a form in the cache.
  */
-function form_get_cache($form_build_id, &$form_state) {
-  if ($cached = cache_get('form_'. $form_build_id, 'cache_form')) {
-    $form = $cached->data;
-    if ($cached = cache_get('storage_'. $form_build_id, 'cache_form')) {
-      $form_state['storage'] = $cached->data;
-    }
-    return $form;
+function form_set_cache($form_build_id, $form, $form_state) {
+  global $user;
+  // 6 hours cache life time for forms should be plenty.
+  $expire = 21600;
+
+  if ($user->uid) {
+    $form['#cache_token'] = drupal_get_token();
+  }
+  cache_set('form_'. $form_build_id, $form, 'cache_form', time() + $expire);
+  if (!empty($form_state['storage'])) {
+    cache_set('storage_'. $form_build_id, $form_state['storage'], 'cache_form', time() + $expire);
   }
 }
 
 /**
- * Store a form in the cache
+ * Fetch a form from cache.
  */
-function form_set_cache($form_build_id, $form, $form_state) {
-  // 6 hours cache life time for forms should be plenty.
-  $expire = 21600;
-
-  cache_set('form_'. $form_build_id, $form, 'cache_form', time() + $expire);
-  if (!empty($form_state['storage'])) {
-    cache_set('storage_'. $form_build_id, $form_state['storage'], 'cache_form', time() + $expire);
+function form_get_cache($form_build_id, &$form_state) {
+  global $user;
+  if ($cached = 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 = cache_get('storage_'. $form_build_id, 'cache_form')) {
+        $form_state['storage'] = $cached->data;
+      }
+      return $form;
+    }
   }
 }
 
@@ -1517,6 +1524,7 @@
 function theme_radio($element) {
   _form_set_class($element, array('form-radio'));
   $output = '<input type="radio" ';
+  $output .= 'id="'. $element['#id'] .'" ';
   $output .= 'name="'. $element['#name'] .'" ';
   $output .= 'value="'. $element['#return_value'] .'" ';
   $output .= (check_plain($element['#value']) == $element['#return_value']) ? ' checked="checked" ' : ' ';
@@ -1733,6 +1741,7 @@
           '#attributes' => $element['#attributes'],
           '#parents' => $element['#parents'],
           '#id' => form_clean_id('edit-'. implode('-', $parents_for_id)),
+          '#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
         );
       }
     }