0

I followed this URL https://magently.com/blog/recaptcha-in-magento-custom-form/ to add google captcha. I created secret keys in google account but unable to see on custom page

    <?= $block->getChildHtml('form.additional.info') ?>
1
  • Hi, Check the captcha code in the msp_recaptcha.phtml file. Commented Dec 30, 2020 at 5:56

2 Answers 2

0

You can add in Custom Form in below way : Add js Using RequireJS.

<html>
   <head>
      <title>reCAPTCHA demo: Explicit render after an onload callback</title>
      <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
         async defer>
      </script>

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous">
      </script>

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js" integrity="sha256-sPB0F50YUDK0otDnsfNHawYmA5M0pjjUf4TvRJkGFrI=" crossorigin="anonymous">
      </script>

      <script type="text/javascript">
         var onloadCallback = function() {
           grecaptcha.render('google_recaptcha', {
             'sitekey' : '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'
           });
         };
      </script>
   </head>
   <body>

      <form action="?" method="POST" id="loginForm">
         <div id="google_recaptcha"></div>
         <br>
         <input type="submit" value="Submit">
      </form>

      <script type="text/javascript">
         $("#loginForm").validate({
            submitHandler: function(form) {
                if (grecaptcha.getResponse()) {
                alert('Captcha Confirmed!');
                //form.submit();
                } 
                else {
                alert('Please confirm captcha to proceed');
                }
            }
         });          
      </script>
   </body>
</html>
0

Please try this blog it work : https://magebug.blogspot.com/2018/05/magento-2-add-google-recaptcha-in.html

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.