Magento – How to use reCaptcha for newsletter subscription form

captchamagento1.9.3.1newsletter

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?

Best Answer

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..

Related Topic