add form function has been altered to avoid checking variable isCaptcha
authorKartik Kathuria <kathuriakartik0@gmail.com>
Sat, 1 May 2021 09:49:40 +0000 (15:19 +0530)
committerKartik Kathuria <kathuriakartik0@gmail.com>
Sat, 1 May 2021 09:49:40 +0000 (15:19 +0530)
CRM/Contribute/Form/Contribution/Main.php
ext/recaptcha/CRM/Utils/ReCAPTCHA.php

index b05aba6bbcc5dab299071126919e1329a7186c42..6f1450dfe6bfe4805b3696a75638e9c29e03e029 100644 (file)
@@ -290,7 +290,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       $this->buildComponentForm($this->_id, $this);
     }
 
-    if (!$this->get_template_vars("isCaptcha") && \Civi::settings()->get('forceRecaptcha')) {
+    if (\Civi::settings()->get('forceRecaptcha')) {
       if (!$this->_userID) {
         CRM_Utils_ReCAPTCHA::enableCaptchaOnForm($this);
       }
index c5e841781892f521fd8e282594173fc56259d0d2..7c77951df4c57cd20c660716895c924060b83b4e 100644 (file)
@@ -62,31 +62,33 @@ class CRM_Utils_ReCAPTCHA {
    */
   public static function add(&$form) {
     $error = NULL;
+
+    // If statement has been altered so that we do not need to check !$this->get_template_vars("isCaptcha") in CRM/Contribute/Form/Contribution/Main.php
     if (!function_exists('recaptcha_get_html')) {
       require_once E::path('lib/recaptcha/recaptchalib.php');
-    }
 
-    // Load the Recaptcha api.js over HTTPS
-    $useHTTPS = TRUE;
+      // Load the Recaptcha api.js over HTTPS
+      $useHTTPS = TRUE;
 
-    $html = recaptcha_get_html(\Civi::settings()->get('recaptchaPublicKey'), $error, $useHTTPS);
+      $html = recaptcha_get_html(\Civi::settings()->get('recaptchaPublicKey'), $error, $useHTTPS);
 
-    $form->assign('recaptchaHTML', $html);
-    $form->assign('recaptchaOptions', \Civi::settings()->get('recaptchaOptions'));
-    $form->add(
-      'text',
-      'g-recaptcha-response',
-      'reCaptcha',
-      NULL,
-      TRUE
-    );
-    $form->registerRule('recaptcha', 'callback', 'validate', 'CRM_Utils_ReCAPTCHA');
-    $form->addRule('g-recaptcha-response', E::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(
+      $form->assign('recaptchaHTML', $html);
+      $form->assign('recaptchaOptions', \Civi::settings()->get('recaptchaOptions'));
+      $form->add(
+        'text',
         'g-recaptcha-response',
-        E::ts('Please go back and complete the CAPTCHA at the bottom of this form.')
+        'reCaptcha',
+        NULL,
+        TRUE
       );
+      $form->registerRule('recaptcha', 'callback', 'validate', 'CRM_Utils_ReCAPTCHA');
+      $form->addRule('g-recaptcha-response', E::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',
+          E::ts('Please go back and complete the CAPTCHA at the bottom of this form.')
+        );
+      }
     }
   }