1

I added in subscribe.phtml

<div class="g-recaptcha" data-sitekey="mysitekey"></div>

and added in local.xml

<block type="core/text" name="google.recaptcha">
    <action method="setText">
         <text><![CDATA[<script src="https://www.google.com/recaptcha/api.js"></script>]]></text>
    </action>
</block>

But it is not working. I can still subscribe to newsletter without captcha answer.

What could be wrong?

1

1 Answer 1

2

I was facing the same issue and I made it solved by installing one extension "Google Invisible reCaptcha"

Wait... I changed few modifications in JS code also.

After installing extension set Site key and secret in admin side and open subscription.phtml

YOUR-PROJECT/app/design/frontend/YOURTHEME/default/template/newsletter/subscribe.phtml

Add code just after Form Tag.

    <div class="g-recaptcha" data-sitekey="YOUR-SITE-KEY"></div>

In the last of file add this JS Snippet.

<script src='https://www.google.com/recaptcha/api.js'></script>
<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('#recaptcha_response_field').addClass('required-captcha-entry');
    })
    var yourFormValidationObj = new VarienForm('newsletter-validate-details');

    Validation.add('required-captcha-entry', ' ', function(v) {
        return !Validation.get('IsEmpty').test(v);
    })
</script>

It worked for me. Cheers if it works for you..

3
  • 1
    Accept answer if it worked for you... Feb 20, 2018 at 4:45
  • I used the above script and got the reCaptcha in my form. But the form captcha validation is not working. @NidhishankerModi can you please help on this? Jun 10, 2020 at 12:54
  • @MagentoUser I added validation code in js script. Validation.add('required-captcha-entry', ' ', function(v) { return !Validation.get('IsEmpty').test(v); }) Make sure there are not two different google captcha comes on a single page. Jun 11, 2020 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy