Index: form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.236
diff -u -r1.236 form.inc
--- form.inc	19 Oct 2007 16:59:28 -0000	1.236
+++ form.inc	20 Oct 2007 08:17:53 -0000
@@ -304,6 +304,11 @@
   if ((!empty($form['#programmed'])) || (!empty($form['#post']) && (isset($form['#post']['form_id']) && ($form['#post']['form_id'] == $form_id)))) {
     drupal_validate_form($form_id, $form, $form_state);
 
+    //if this form is being previewed and/or redrawn as a result of validation errors
+    //flush the static variable inside of form_clean_id so that the system doesn't 'think'
+    //that element IDs already exist
+    form_clean_id(NULL, TRUE);
+
     if ((!empty($form_state['submitted'])) && !form_get_errors() && empty($form_state['rebuild'])) {
       $form_state['redirect'] = NULL;
       form_execute_handlers('submit', $form, $form_state);
@@ -2007,12 +2012,20 @@
  *
  * @param $id
  *   The ID to clean.
+ * @param boolean $flush
+ *   If set to true, the function will flush and reset the static array which is built to test the uniqueness
+ *   of element IDs.  This is only ever used if a form has completed the validation process. This parameter
+ *   should never be set to true if this function is being called to assign an ID to the #ID element.
  * @return
  *   The cleaned ID.
  */
-function form_clean_id($id = NULL) {
+function form_clean_id($id = NULL, $flush = FALSE) {
   static $seen_ids = array();
 
+  if ($flush) {
+    $seen_ids = array();
+    return;
+  }
   $id = str_replace(array('][', '_', ' '), '-', $id);
 
   // Ensure id's are unique. The first occurrence is held but left alone.
