X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FReCAPTCHA.php;h=882556e0e4f6190b96fa26d17c749b8a4cacf27a;hb=f377f10d244045a52b5891bdeedc823b3988bd7c;hp=213f7e60bb9bd4442341f65d46d91d24eb4a4dab;hpb=e44431fee3e48e503e8500ace6206f2d25c8956f;p=civicrm-core.git diff --git a/CRM/Utils/ReCAPTCHA.php b/CRM/Utils/ReCAPTCHA.php index 213f7e60bb..882556e0e4 100644 --- a/CRM/Utils/ReCAPTCHA.php +++ b/CRM/Utils/ReCAPTCHA.php @@ -1,7 +1,7 @@ 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 - ); + 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.') + ); + } } - /** - * @param $value - * @param CRM_Core_Form $form - * - * @return mixed - */ - 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; - } } -