$config = CRM_Core_Config::singleton();
$useSSL = FALSE;
if (!function_exists('recaptcha_get_html')) {
- require_once 'packages/recaptcha/recaptchalib.php';
+ require_once 'recaptcha/recaptchalib.php';
}
// Load the Recaptcha api.js over HTTPS
TRUE
);
$form->registerRule('recaptcha', 'callback', 'validate', 'CRM_Utils_ReCAPTCHA');
+ $form->addRule('g-recaptcha-response', ts('Please go back and complete the CAPTCHA at the bottom of this form.'), 'recaptcha');
if ($form->isSubmitted() && empty($form->_submitValues['g-recaptcha-response'])) {
$form->setElementError(
'g-recaptcha-response',
}
}
+ /**
+ * @param $value
+ * @param CRM_Core_Form $form
+ *
+ * @return mixed
+ */
+ public static function validate($value, $form) {
+ $resp = recaptcha_check_answer(CRM_Core_Config::singleton()->recaptchaPrivateKey,
+ $_SERVER['REMOTE_ADDR'],
+ $_POST['g-recaptcha-response']
+ );
+ return $resp->is_valid;
+ }
+
}