Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.267
diff -u -p -r1.267 form.inc
--- includes/form.inc	12 Feb 2008 13:52:32 -0000	1.267
+++ includes/form.inc	7 Mar 2008 16:46:52 -0000
@@ -1532,10 +1532,18 @@ function theme_radios($element) {
   if (isset($element['#attributes']['class'])) {
     $class .= ' '. $element['#attributes']['class'];
   }
-  $element['#children'] = '<div class="'. $class .'">'. (!empty($element['#children']) ? $element['#children'] : '') .'</div>';
-  if ($element['#title'] || $element['#description']) {
-    unset($element['#id']);
-    return theme('form_element', $element, $element['#children']);
+  // will this be themed as a form element?
+  $theme_form_element = ($element['#title'] || $element['#description']);
+  $id = '';
+  // if we are _not_ themeing as a form element, we need to put the id into the div
+  if (!$theme_form_element) {
+    $id = ' id="'. $element['#id'] . '"';
+  }
+  $element['#children'] = '<div class="'. $class .'"'. $id .'>'. (!empty($element['#children']) ? $element['#children'] : '') .'</div>';
+  if ($theme_form_element) {
+    $form_element = theme('form_element', $element, $element['#children']);
+    $form_element = strtr($form_element, array(' for="' . $element['#id'] .'"' => ''));
+    return $form_element;
   }
   else {
     return $element['#children'];
@@ -1869,10 +1877,18 @@ function theme_checkboxes($element) {
   if (isset($element['#attributes']['class'])) {
     $class .= ' '. $element['#attributes']['class'];
   }
-  $element['#children'] = '<div class="'. $class .'">'. (!empty($element['#children']) ? $element['#children'] : '') .'</div>';
-  if ($element['#title'] || $element['#description']) {
-    unset($element['#id']);
-    return theme('form_element', $element, $element['#children']);
+  // will this be themed as a form element?
+  $theme_form_element = ($element['#title'] || $element['#description']);
+  $id = '';
+  // if we are _not_ themeing as a form element, we need to put the id into the div
+  if (!$theme_form_element) {
+    $id = ' id="'. $element['#id'] . '"';
+  }
+  $element['#children'] = '<div class="'. $class .'"'. $id .'>'. (!empty($element['#children']) ? $element['#children'] : '') .'</div>';
+  if ($theme_form_element) {
+    $form_element = theme('form_element', $element, $element['#children']);
+    $form_element = strtr($form_element, array(' for="' . $element['#id'] .'"' => ''));
+    return $form_element;
   }
   else {
     return $element['#children'];
