Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.486
diff -u -p -r1.486 form.inc
--- includes/form.inc	30 Aug 2010 05:52:35 -0000	1.486
+++ includes/form.inc	30 Aug 2010 13:32:36 -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,28 @@ 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) {
+  // 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);
+  }
+}
+
+/**
Index: modules/simpletest/tests/form.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/form.test,v
retrieving revision 1.62
diff -u -p -r1.62 form.test
--- modules/simpletest/tests/form.test	27 Aug 2010 11:54:32 -0000	1.62
+++ modules/simpletest/tests/form.test	30 Aug 2010 13:32:36 -0000
@@ -622,11 +622,11 @@ class FormsElementsTableSelectFunctional
     );
 
     // Test with a valid value.
-    list($processed_form, $form_state, $errors) = $this->formSubmitHelper($form, array('tableselect' => array('row1' => 'row1')));
+    list($processed_form, $form_state, $errors) = $this->formSubmitHelper($form, array('tableselect' => array('row1')));
     $this->assertFalse(isset($errors['tableselect']), t('Option checker allows valid values for checkboxes.'));
 
     // Test with an invalid value.
-    list($processed_form, $form_state, $errors) = $this->formSubmitHelper($form, array('tableselect' => array('non_existing_value' => 'non_existing_value')));
+    list($processed_form, $form_state, $errors) = $this->formSubmitHelper($form, array('tableselect' => array('non_existing_value')));
     $this->assertTrue(isset($errors['tableselect']), t('Option checker disallows invalid values for checkboxes.'));
 
   }
