4

I just want to know how can I add captcha on mage_newsletter on each page of site. Here my .xml code block for view captcha

  <block type="core/text_list" name="form.additional.info">
        <block type="captcha/captcha" name="captcha">
            <reference name="head">
                <action method="addJs"><file>mage/captcha.js</file></action>
            </reference>
            <action method="setFormId"><formId>contacts</formId></action>
            <action method="setImgWidth"><width>230</width></action>
            <action method="setImgHeight"><width>50</width></action>
        </block>
    </block>
0

I was facing the same issue and I made it solved 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..

  • Could you expand on the one extension "Google Invisible reCaptcha". – Vaishal Patel Aug 8 '18 at 10:22
  • Does this extension work on localhost? – aravind May 10 at 5:29
  • Yes @aravind, it works. In case if you would like to run Captcha in Localhost you need to pass localhost in the trusted URL under Google Developer Account. 1. Go to your google reCaptcha admin panel 2. Add localhost & 127.0.0.1 to domains of a new site like the following image – Nidhishanker Modi May 10 at 10:01
  • @Nidhishanker Modi Ok let me try this solution.. – aravind May 10 at 11:41
  • Yes, Let me know if it is not working for you @aravind – Nidhishanker Modi May 10 at 13:01

Your Answer

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

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