Index: captcha.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/captcha.module,v
retrieving revision 1.42.2.37
diff -u -u -p -r1.42.2.37 captcha.module
--- captcha.module	24 Oct 2007 20:15:11 -0000	1.42.2.37
+++ captcha.module	17 Nov 2007 19:34:17 -0000
@@ -16,6 +16,10 @@ define('CAPTCHA_PERSISTENCE_SHOW_ALWAYS'
 define('CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM', 2);
 define('CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL', 3);
 
+define('CAPTCHA_FAILURE_REACTION_FORM_ERROR', 1);
+define('CAPTCHA_FAILURE_REACTION_SPARTAN403', 2);
+define('CAPTCHA_FAILURE_REACTION_DRUPAL_ACCESS_DENIED', 3);
+
 /**
  * Implementation of hook_help().
  */
@@ -279,6 +283,18 @@ function captcha_admin_settings() {
     '#description' => t('Report information about wrong responses to the !watchdoglog.', array('!watchdoglog' => l('log', 'admin/logs/watchdog'))),
     '#default_value' => variable_get('captcha_log_wrong_responses', FALSE),
   );
+  // option for how to react on a wrong answer
+  $form['captcha_reaction_on_wrong_response'] = array(
+    '#type' => 'radios',
+    '#title' => t('Reaction on wrong response'),
+    '#options' => array(
+      CAPTCHA_FAILURE_REACTION_FORM_ERROR => t('Reshow form with error message (default Drupal behavior).'),
+      CAPTCHA_FAILURE_REACTION_DRUPAL_ACCESS_DENIED => t('Show the <a href="!errorreporting">access denied error page</a>.', array('!errorreporting' => url('admin/settings/error-reporting'))),
+      CAPTCHA_FAILURE_REACTION_SPARTAN403 => t('Show bare error message (with HTTP status code 403).'),
+    ),
+    '#default_value' => variable_get('captcha_reaction_on_wrong_response', CAPTCHA_FAILURE_REACTION_FORM_ERROR),
+    '#description' => t('Reduce the resources spent on spam bots by choosing a lighter wrong response error page. Note that this also reduces the usability for human users.'),
+  );
   // submit button
   $form['submit'] = array(
     '#type' => 'submit',
@@ -329,6 +345,7 @@ function captcha_admin_settings_submit($
       variable_set('captcha_description', $form_values['captcha_description']);
     }
     variable_set('captcha_persistence', $form_values['captcha_persistence']);
+    variable_set('captcha_reaction_on_wrong_response', $form_values['captcha_reaction_on_wrong_response']);
     variable_set('captcha_log_wrong_responses', $form_values['captcha_log_wrong_responses']);
     drupal_set_message(t('The CAPTCHA settings were saved.'), 'status');
   }
@@ -542,6 +559,27 @@ function captcha_form_alter($form_id, &$
 }
 
 /**
+ * Helper function for reacting on validate errors
+ */
+function _captcha_form_set_error($name, $message) {
+  switch (variable_get('captcha_reaction_on_wrong_response', CAPTCHA_FAILURE_REACTION_FORM_ERROR)) {
+    case CAPTCHA_FAILURE_REACTION_FORM_ERROR:
+      form_set_error($name, $message);
+      break;
+    case CAPTCHA_FAILURE_REACTION_SPARTAN403:
+      header('HTTP/1.1 403 Forbidden');
+      print $message;
+      // stop further validation, processing and subsequent form rendering
+      exit();
+      break;
+    case CAPTCHA_FAILURE_REACTION_DRUPAL_ACCESS_DENIED:
+      drupal_access_denied();
+      exit();
+      break;
+  }
+}
+
+/**
  * Implementation of form #validate.
  */
 function captcha_validate($form_values) {
@@ -555,7 +593,7 @@ function captcha_validate($form_values) 
   $captcha_token = $form_values['#post']['captcha_token'];
   // Check if captcha_token exists
   if (!isset($_SESSION['captcha'][$form_id][$captcha_token])) {
-    form_set_error('captcha_token', t('Invalid CAPTCHA token.'));
+    _captcha_form_set_error('captcha_token', t('Invalid CAPTCHA token.'));
   }
   // Check answer
   if ($captcha_response === $_SESSION['captcha'][$form_id][$captcha_token]) {
@@ -564,7 +602,7 @@ function captcha_validate($form_values) 
   }
   else {
     // set form error
-    form_set_error('captcha_response', t('The answer you entered for the CAPTCHA was not correct.'));
+    _captcha_form_set_error('captcha_response', t('The answer you entered for the CAPTCHA was not correct.'));
     // update wrong response counter
     variable_set('captcha_wrong_response_counter', variable_get('captcha_wrong_response_counter', 0) + 1);
     // log to watchdog if needed
