From 3c275f0d154cde1b2a5c17c5e3c444f17cf65ab1 Mon Sep 17 00:00:00 2001 From: Web Access Date: Tue, 27 Jan 2015 19:43:17 +0530 Subject: [PATCH] CRM-15853 --- CRM/Utils/ReCAPTCHA.php | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/CRM/Utils/ReCAPTCHA.php b/CRM/Utils/ReCAPTCHA.php index 2d48759f59..c04a181c9d 100644 --- a/CRM/Utils/ReCAPTCHA.php +++ b/CRM/Utils/ReCAPTCHA.php @@ -89,41 +89,18 @@ class CRM_Utils_ReCAPTCHA { $form->assign('recaptchaOptions', $config->recaptchaOptions); $form->add( 'text', - 'recaptcha_challenge_field', - NULL, + 'g-recaptcha-response', + 'reCaptcha', NULL, TRUE ); - $form->add( - 'hidden', - 'recaptcha_response_field', - 'manual_challenge' - ); - $form->registerRule('recaptcha', 'callback', 'validate', 'CRM_Utils_ReCAPTCHA'); - $form->addRule( - 'recaptcha_challenge_field', - ts('Input text must match the phrase in the image. Please review the image and re-enter matching text.'), - 'recaptcha', - $form - ); - } - - /** - * @param $value - * @param CRM_Core_Form $form - * - * @return mixed - */ - public static function validate($value, $form) { - $config = CRM_Core_Config::singleton(); - - $resp = recaptcha_check_answer($config->recaptchaPrivateKey, - $_SERVER['REMOTE_ADDR'], - $_POST["recaptcha_challenge_field"], - $_POST["recaptcha_response_field"] - ); - return $resp->is_valid; + if ($form->isSubmitted() && empty($form->_submitValues['g-recaptcha-response'])) { + $form->setElementError( + 'g-recaptcha-response', + ts('Input text must match the phrase in the image. Please review the image and re-enter matching text.') + ); + } } } -- 2.25.1