Index: recaptcha.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/recaptcha/Attic/recaptcha.module,v retrieving revision 1.13.2.4.2.11.2.4 diff -u -b -u -p -r1.13.2.4.2.11.2.4 recaptcha.module --- recaptcha.module 2 Feb 2009 22:39:42 -0000 1.13.2.4.2.11.2.4 +++ recaptcha.module 21 May 2009 20:10:36 -0000 @@ -183,33 +183,19 @@ function recaptcha_captcha() { } // Create the form - $result['preprocess'] = TRUE; // tell captcha to preprocess the form $result['solution'] = TRUE; // require TRUE to be returned - $result['form']['captcha_challenge'] = array( + $result['form']['captcha_response'] = array( '#type' => 'item', '#description' => recaptcha_get_html($recaptcha_public_key, NULL, $recaptcha_secure_connection), '#required' => TRUE, '#value' => $recaptcha_form_value ? '
'. $recaptcha_form_value .'
' : NULL, + // Make sure this 'item' form element is handled as an input element + // so that a '#process' callback can be attached. + '#input' => TRUE, + '#process' => array('recaptcha_process'), ); } return $result; - - case 'preprocess': - require_once('recaptcha.inc'); - @(include_once('recaptcha/recaptchalib.php')) or _recaptcha_library_not_found(); - $resp = recaptcha_check_answer( - variable_get('recaptcha_private_key', ''), - $_SERVER['REMOTE_ADDR'], - $_POST['recaptcha_challenge_field'], - $_POST['recaptcha_response_field']); - if ($resp->is_valid) { - return TRUE; - } - else { - form_set_error('captcha_response', t('The reCAPTCHA code you entered was incorrect.')); - return FALSE; - } - break; } } // function recaptcha_captcha @@ -247,3 +233,28 @@ function theme_recaptcha_custom_widget()
$help
EOT; } + +/** + * Callback function for fetching the validation result from reCAPTCHA server + * and passing it to the Drupal CAPTCHA API. + */ +function recaptcha_process($element, $edit, &$form_state, $complete_form) { + if (isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_response_field'])) { + require_once('recaptcha.inc'); + @(include_once('recaptcha/recaptchalib.php')) or _recaptcha_library_not_found(); + $resp = recaptcha_check_answer( + variable_get('recaptcha_private_key', ''), + $_SERVER['REMOTE_ADDR'], + $_POST['recaptcha_challenge_field'], + $_POST['recaptcha_response_field'] + ); + if ($resp->is_valid) { + $element['#value'] = TRUE; + } + else { + form_set_error('captcha_response', t('The reCAPTCHA code you entered was incorrect.')); + $element['#value'] = FALSE; + } + } + return $element; +}