Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.497 diff -u -p -r1.497 form.inc --- includes/form.inc 27 Sep 2010 00:53:55 -0000 1.497 +++ includes/form.inc 29 Sep 2010 12:17:02 -0000 @@ -1154,7 +1154,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.')); @@ -2128,6 +2128,38 @@ 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 default value uses the keys of the #default_value property. This + // differs from the checkboxes element which uses the array values. + 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. *