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.

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>
  • Let me try with your solution. – Vivek May 10 at 11:25
  • Does the above solution works? – aravind May 10 at 11:41
  • This works on the home page only because of you added cms_index_index layout. – Ronak May 10 at 11:49
  • Yes, Because of @Vivek has added cms_index_index in his layout. – H_Parekh May 10 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. – H_Parekh May 10 at 11:56

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.