Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.402
diff -u -p -r1.402 form.inc
--- includes/form.inc	21 Nov 2009 14:06:45 -0000	1.402
+++ includes/form.inc	21 Nov 2009 22:36:44 -0000
@@ -1109,10 +1109,11 @@ function form_builder($form_id, $element
       // Check to see if a tree of child elements is present. If so,
       // continue down the tree if required.
       $element[$key]['#parents'] = $element[$key]['#tree'] && $element['#tree'] ? array_merge($element['#parents'], array($key)) : array($key);
-      $array_parents = isset($element['#array_parents']) ? $element['#array_parents'] : array();
-      $array_parents[] = $key;
-      $element[$key]['#array_parents'] = $array_parents;
     }
+    // Ensure #array_parents follows the actual form structure.
+    $array_parents = isset($element['#array_parents']) ? $element['#array_parents'] : array();
+    $array_parents[] = $key;
+    $element[$key]['#array_parents'] = $array_parents;
 
     // Assign a decimal placeholder weight to preserve original array order.
     if (!isset($element[$key]['#weight'])) {
