Index: grid.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/components/grid.inc,v
retrieving revision 1.3.2.7
diff -u -r1.3.2.7 grid.inc
--- grid.inc	17 Aug 2008 19:15:37 -0000	1.3.2.7
+++ grid.inc	6 Sep 2008 02:41:23 -0000
@@ -63,10 +63,26 @@
   $options = _webform_grid_options($component['extra']['options']);
 
   if ($component['extra']['optrand'] && $random) {
-    shuffle($options);
+    // This maneuver shuffles the array keys, then uses them as
+    // the basis for ordering the options.
+    $aux = array();
+    $keys = array_keys($options);
+    shuffle($keys);
+    foreach($keys as $key) {
+      $aux[$key] = $options[$key];
+      unset($options[$key]);
+    }
+    $options = $aux;
   }
   if ($component['extra']['qrand'] && $random) {
-    shuffle($questions);
+    $aux = array();
+    $keys = array_keys($questions);
+    shuffle($keys);
+    foreach($keys as $key) {
+      $aux[$key] = $questions[$key];
+      unset($questions[$key]);
+    }
+    $questions = $aux;
   }
   foreach ($questions as $question) {
     if ($question != '') {
@@ -120,6 +136,7 @@
  **/
 function _webform_submit_grid(&$data, $component) {
   $options = drupal_map_assoc(array_flip(_webform_select_options($component['extra']['options'])));
+  $questions = drupal_map_assoc(array_flip(_webform_select_options($component['extra']['questions'])));
 
   if (is_array($data)) {
     foreach ($data as $key => $value) {
@@ -131,6 +148,13 @@
   elseif (!empty($data)) {
     $data = $options[$data];
   }
+
+  // Put the form in the original option order before saving.
+  $order = $questions;
+  foreach ($data as $key => $value) {
+    $order[$key] = $value;
+  }
+  $data = $order;
 }
 /**
  * Format the output of emailed data for this component.
