0

I've added captcha to contact us form by following this

I'm wondering while its not working with newsletter form ?

here's what I tried.

<cms_index_index translate="label">
        <reference name="newsletter-validate-detail">
               <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>newsletter_captcha</formId></action>
                    <action method="setImgWidth"><width>230</width></action>
                    <action method="setImgHeight"><width>50</width></action>
                </block>
            </block> 
        </reference>
    </cms_index_index>

config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Contact_Captcha>
        <version>0.1.0</version>
    </Contact_Captcha>
</modules>
<default>
    <captcha>
        <frontend>
            <areas>
                <contact_page_captcha>
                    <label>Contact Page</label>
                </contact_page_captcha>
                <newsletter_captcha>
                    <label>Newsletter Form</label>
                </newsletter_captcha>
            </areas>
        </frontend>
    </captcha>
</default>
 <global>
    <models>
        <contact_captcha>
            <class>Contact_Captcha_Model</class>
        </contact_captcha>
    </models>
    <events>
        <controller_action_predispatch_contacts_index_post>
            <observers>
                <captcha>
                    <type>model</type>
                    <class>contact_captcha/observer</class>
                    <method>checkContactPage</method>
                </captcha>
            </observers>
        </controller_action_predispatch_contacts_index_post>
        <controller_action_predispatch_newsletter_subscriber_new>
            <observers>
                <captchanews>
                    <type>model</type>
                    <class>contact_captcha/newsletterObserver</class>
                    <method>checkNewsletterPage</method>
                </captchanews>
            </observers>
        </controller_action_predispatch_newsletter_subscriber_new>
    </events>
</global>
</config>

Any help would be appreciated.

3
  • Are you showing the newsletter form in contact us page alone or in all pages under footer?
    – mydons
    Commented May 10, 2019 at 10:13
  • Yes In footer newsletter at all pages. not included in to contact form.
    – anonymous
    Commented May 10, 2019 at 11:25
  • check this: magento.stackexchange.com/questions/133238/…
    – Saphal Jha
    Commented May 10, 2019 at 11:44

1 Answer 1

1

Try below code in your layout file. Changed <reference name="newsletter-validate-detail"> to <reference name="footer.newsletter">

<cms_index_index translate="label">
            <reference name="footer.newsletter">
                   <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>newsletter_captcha</formId></action>
                        <action method="setImgWidth"><width>230</width></action>
                        <action method="setImgHeight"><width>50</width></action>
                    </block>
                </block> 
            </reference>
        </cms_index_index>
8
  • Let me try with your solution.
    – anonymous
    Commented May 10, 2019 at 11:25
  • Does the above solution works?
    – aravind
    Commented May 10, 2019 at 11:41
  • This works on the home page only because of you added cms_index_index layout.
    – Ronak
    Commented May 10, 2019 at 11:49
  • Yes, Because of @Vivek has added cms_index_index in his layout. Commented May 10, 2019 at 11:53
  • If you want to show on all page then remove cms_index_index from layout and put rest of the code under <default></default> tag. Commented May 10, 2019 at 11:56

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.