0

I have been trying to add google recaptcha on magento checkout page where payment methods are toggled, I'm trying to invoke google re-captcha when a button is clicked but it goes through without captcha as required field before continuing, any help would be appreciated?

HTML

<button type="button" class="button" onclick="payment.save()"><span><span><?php echo $this->__('Continue') ?></span></span></button>

Google Recaptcha Code

 <script src='https://www.google.com/recaptcha/api.js'></script>
        <?php if ($this->helper('recaptcha')->showOnOnepage() == 1) { ?>
             <li id="rcode">
                 <div class="captcha">
                      <div class="g-recaptcha" data-sitekey="<?php echo $this->helper('recaptcha')->getKey(); ?>"
                           data-theme="<?php echo($this->helper('recaptcha')->getTheme()); ?>"></div>
                      </div>
                 <span id="captcha-required" style='display:none; color:#ff0000'><?php echo $this->__('Please Fill Recaptcha To Continue'); ?></span>
             </li>
        <?php } ?>

Onclick function

<script type="text/javascript">
        jQuery('.btn').click(function () {
            var payment = new Payment('co-payment-form', '<?php echo $this->getUrl('checkout/onepage/savePayment') ?>');
        <?php
            if($this->helper('recaptcha')->showOnOnepage() == 0){ ?>
            payment.save();
            <?php } else { ?>
            if (grecaptcha.getResponse() != "") {
                payment.save();
            }
            else {
                document.getElementById("captcha-required").style.display = "block";
            }
        <?php } ?>
        });
    </script>
2
  • First time when page is load, does it show there or not? Jul 14, 2021 at 4:02
  • Yes, it shows perfectly on the checkout page but it is not linked to clicking "Continue" button. It let go continuing to next phase without acknowledging captcha in place. Jul 14, 2021 at 22:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.