Index: captcha.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/captcha.module,v
retrieving revision 1.100
diff -u -b -u -p -r1.100 captcha.module
--- captcha.module	20 Sep 2009 10:57:07 -0000	1.100
+++ captcha.module	5 Oct 2009 21:33:44 -0000
@@ -193,13 +193,14 @@ function captcha_process($element, $edit
 
   // Retrieve CAPTCHA session ID from posted data or generate it, if not available.
   $this_form_id = $complete_form['form_id']['#value'];
-  // Previously $element['#post']['form_id'] and $element['#post']['captcha_sid']
-  // were used here, but those entry are not available in node preview situations so
-  // we use $form_state['clicked_button']['#post']['form_id'] and
-  // $form_state['clicked_button']['#post']['captcha_sid'] instead.
-  $posted_form_id = (isset($form_state['clicked_button']['#post']['form_id']) ? $form_state['clicked_button']['#post']['form_id'] : NULL);
-  if ($this_form_id == $posted_form_id && isset($form_state['clicked_button']['#post']['captcha_sid'])) {
-    $captcha_sid = $form_state['clicked_button']['#post']['captcha_sid'];
+  // Previously, $posted_form_id and $posted_captcha_sid were retrieved from
+  // $element['#post']['form_id'] and $element['#post']['captcha_sid'],
+  // but those entry are not available in node preview situations, so
+  // we use $form_state and the _captcha_get_posted_captcha_info() function.
+  list($posted_form_id, $posted_captcha_sid) = _captcha_get_posted_captcha_info($form_state);
+  if ($this_form_id == $posted_form_id && isset($posted_captcha_sid)) {
+    // Reuse the posted CAPTCHA session.
+    $captcha_sid = $posted_captcha_sid;
   } else {
     // Generate new CAPTCHA session.
     $captcha_sid = _captcha_generate_captcha_session($this_form_id, CAPTCHA_STATUS_UNSOLVED);
@@ -394,6 +395,31 @@ function captcha_validate_case_insensiti
 }
 
 /**
+ * Get the posted CAPTCHA info (posted form_id and CAPTCHA sessions ID)
+ * from the posted form.
+ *
+ * @param $form_state the form state structure to extract the info from.
+ * @return an array with $posted_form_id and $post_captcha_sid with NULL values
+ *     if the values could not be found.
+ */
+function _captcha_get_posted_captcha_info($form_state) {
+  // Get the posted data array.
+  // In most cases, $form_state['clicked_button']['#post'] should do the job,
+  // However, with Internet Explorer 7, when submitting a form with the enter
+  // key instead of a submit button, we also have to check an other place.
+  if (isset($form_state['clicked_button']['#post'])) {
+    $post_data = $form_state['clicked_button']['#post'];
+  }
+  else if (isset($form_state['buttons']['button']['0']['#post'])) {
+    $post_data = $form_state['buttons']['button']['0']['#post'];
+  }
+  // Return the posted form_id and CAPTCHA session ID.
+  $posted_form_id = isset($post_data['form_id']) ? $post_data['form_id'] : NULL;
+  $posted_captcha_sid = isset($post_data['captcha_sid']) ? $post_data['captcha_sid'] : NULL;
+  return array($posted_form_id, $posted_captcha_sid);
+}
+
+/**
  * CAPTCHA validation handler.
  *
  * This function is placed in the main captcha.module file to make sure that
@@ -401,7 +427,6 @@ function captcha_validate_case_insensiti
  * captcha_form_alter(), and subsequently don't include additional include
  * files).
  */
-
 function captcha_validate($element, &$form_state) {
   $captcha_info = $element['#captcha_info'];
   $form_id = $captcha_info['form_id'];
@@ -409,15 +434,16 @@ function captcha_validate($element, &$fo
   // Get CAPTCHA response.
   $captcha_response = $form_state['values']['captcha_response'];
 
-  // We use $form_state['clicked_button']['#post']['captcha_sid']
-  // instead of $form_state['values']['captcha_sid'] because the latter
-  // contains the captcha_sid associated to the 'newly' generated element,
+  // We use the posted CAPTCHA session ID instead of
+  // $form_state['values']['captcha_sid'] because the latter contains the
+  // captcha_sid associated to the 'newly' generated element,
   // while the former contains the captcha_sid of the posted form.
   // In most cases both will be the same because of persistence.
   // However, they will differ when the life span of the CAPTCHA session
   // does not equal the life span of a multipage form and then we have to
   // pick the right one.
-  $csid = $form_state['clicked_button']['#post']['captcha_sid'];
+  list($posted_form_id, $posted_captcha_sid) = _captcha_get_posted_captcha_info($form_state);
+  $csid = $posted_captcha_sid;
 
   $solution = db_result(db_query('SELECT solution FROM {captcha_sessions} WHERE csid = %d AND status = %d', $csid, CAPTCHA_STATUS_UNSOLVED));
 
