CRM-15853
authorWeb Access <rohan.katkar@webaccessglobal.com>
Tue, 27 Jan 2015 14:13:17 +0000 (19:43 +0530)
committerWeb Access <rohan.katkar@webaccessglobal.com>
Tue, 27 Jan 2015 14:13:17 +0000 (19:43 +0530)
CRM/Utils/ReCAPTCHA.php

index 2d48759f59c23d8cc3f0185ed9106b576f4c65a7..c04a181c9dd8901b70dcb7382d906d143802917a 100644 (file)
@@ -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.')
+      );
+    }
   }
 
 }