Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.487
diff -u -p -r1.487 form.inc
--- includes/form.inc	30 Aug 2010 17:07:49 -0000	1.487
+++ includes/form.inc	1 Sep 2010 13:45:50 -0000
@@ -1089,7 +1089,7 @@ function _form_validate(&$elements, &$fo
           $options = $elements['#options'];
         }
         if (is_array($elements['#value'])) {
-          $value = $elements['#type'] == 'checkboxes' ? array_keys($elements['#value']) : $elements['#value'];
+          $value = in_array($elements['#type'], array('checkboxes', 'tableselect')) ? array_keys($elements['#value']) : $elements['#value'];
           foreach ($value as $v) {
             if (!isset($options[$v])) {
               form_error($elements, $t('An illegal choice has been detected. Please contact the site administrator.'));
@@ -2036,6 +2036,49 @@ function form_type_checkboxes_value($ele
 }
 
 /**
+ * Helper function to determine the value for a tableselect form element.
+ *
+ * @param $element
+ *   The form element whose value is being populated.
+ * @param $input
+ *   The incoming input to populate the form element. If this is FALSE,
+ *   the element's default value should be returned.
+ * @return
+ *   The data that will appear in the $element_state['values'] collection
+ *   for this element. Return nothing to use the default.
+ */
+function form_type_tableselect_value($element, $input = FALSE) {
+  // The enabled code in this routine gets the default value from the keys of
+  // the #default_value property. This differs from the checkboxes element which
+  // uses the array values. For D8, consider making the two elements consistent
+  // with the following disabled code.
+
+  // If #multiple is FALSE. the tableselect element displays a set of radio
+  // buttons which constitue a single value element, and for which the default
+  // value handling is sufficient.
+  // if (isset($element['#multiple']) && $element['#multiple']) {
+  //   // Multiple value element, a set of checkboxes.
+  //   return form_type_checkboxes_value($element, $input);
+  // }
+
+  if (isset($element['#multiple']) && $element['#multiple']) {
+    if ($input === FALSE) {
+      $value = array();
+      $element += array('#default_value' => array());
+      foreach ($element['#default_value'] as $key => $flag) {
+        if ($flag) {
+          $value[$key] = $key;
+        }
+      }
+      return $value;
+    }
+    else {
+      return is_array($input) ? drupal_map_assoc($input) : array();
+    }
+  }
+}
+
+/**
  * Helper function to determine the value for a password_confirm form
  * element.
  *
