Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.514
diff -u -p -r1.514 form.inc
--- includes/form.inc	8 Dec 2010 06:55:01 -0000	1.514
+++ includes/form.inc	12 Dec 2010 21:16:05 -0000
@@ -661,9 +661,14 @@ function drupal_form_submit($form_id, &$
   // Merge in default values.
   $form_state += form_state_defaults();
 
-  $form = drupal_retrieve_form($form_id, $form_state);
+  // Since we are processing the form right after building it, we populate
+  // $form_state['input'] before calling the form builder function, so that the
+  // form builder receives it the same way it normally would when the form is
+  // being built for validation and submission.
   $form_state['input'] = $form_state['values'];
+
   $form_state['programmed'] = TRUE;
+  $form = drupal_retrieve_form($form_id, $form_state);
   // Programmed forms are always submitted.
   $form_state['submitted'] = TRUE;
 
@@ -1799,13 +1804,15 @@ function form_builder($form_id, &$elemen
       $element['#attributes']['enctype'] = 'multipart/form-data';
     }
 
-    // If a form contains a single textfield, and the ENTER key is pressed
-    // within it, Internet Explorer submits the form with no POST data
-    // identifying any submit button. Other browsers submit POST data as though
-    // the user clicked the first button. Therefore, to be as consistent as we
-    // can be across browsers, if no 'triggering_element' has been identified
-    // yet, default it to the first button.
-    if (!$form_state['programmed'] && !isset($form_state['triggering_element']) && !empty($form_state['buttons'])) {
+    // Programmatic form sumbissions made using drupal_form_submit() often do
+    // not specify the submit button that was "clicked". In addition, if a form
+    // contains a single textfield, and the ENTER key is pressed within it,
+    // Internet Explorer submits the form with no POST data identifying any
+    // submit button. Other browsers submit POST data as though the user
+    // clicked the first button. Therefore, to be as consistent as we can be
+    // across browsers, if no 'triggering_element' has been identified yet,
+    // default it to the first button.
+    if (!isset($form_state['triggering_element']) && !empty($form_state['buttons'])) {
       $form_state['triggering_element'] = $form_state['buttons'][0];
     }
 
