Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.297
diff -u -r1.297 form.inc
--- includes/form.inc	15 Oct 2008 14:17:26 -0000	1.297
+++ includes/form.inc	23 Oct 2008 16:30:35 -0000
@@ -913,6 +913,12 @@
       // later.
       unset($form['#sorted']);
     }
+
+    // Assign the key of the element.
+    if (!isset($form[$key]['#key'])) {
+      $form[$key]['#key'] = $key;
+    }
+
     $form[$key] = form_builder($form_id, $form[$key], $form_state);
     $count++;
   }
@@ -1516,6 +1522,11 @@
     }
   }
 
+  // Create the element ID from the element's key.
+  if (!isset($element['#attributes']['id']) && isset($element['#key'])) {
+    $element['#attributes']['id'] = form_clean_id($element['#key']);
+  }
+
   return '<fieldset' . drupal_attributes($element['#attributes']) . '>' . ($element['#title'] ? '<legend>' . $element['#title'] . '</legend>' : '') . (isset($element['#description']) && $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '') . (!empty($element['#children']) ? $element['#children'] : '') . (isset($element['#value']) ? $element['#value'] : '') . "</fieldset>\n";
 }
 
