0

I added a captcha on the contact-us page following the guide here: How to implement Magento Captcha in Contact- Us form?

it seems to be working perfectly, the problem is that I have another CMS-page that calls the same contact-us form template like this:

{{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}}

the problem is that the captcha is not working on that page, yet it keeps working on the default contact-us page, even if the form should be the same.

0

In Magento, every element on the page is shown on the basis of layout handle, by which it has been called.

For example: if captcha has been called on the action /contacts, then the layout handle contacts_index_index will be able to show captcha.

To call captcha for contact form in the cms page, you would need to write layout update for the cms page.

Update: You need to go to the cms page, click on the Design tab and enter the layout update XML in the Custom Layout Update XML textarea.

<reference name="content">
    <block type="core/template" name="contactForm">
        <action method="setTemplate">
            <template>contactcaptcha/contacts/form.phtml</template>
        </action>
        <action method="setFormAction">
            <form_action>contacts/index/post</form_action>
        </action>
        <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>
    </block>
</reference>

Next, click on Content tab and put &nbsp; in the textarea.

Then click on Save Page button and flush Magento Cache.

Note: Even though the form will start showing captcha on the page, but after submitting the form, it will redirect to the default contacts page.

Note: Every time when you will open the cms page, you need to put &nbsp; in the textarea before saving the page.

Please let me know if it helped.

  • It already works on the /contacts page, as I already have a "contacts_index_index" handle, I want it to work on a page which page key is "company", tried writing a handle called "company_index_index", but doesn't seem to work – Arnold.M Jun 26 '18 at 11:33
  • Since "company" is a cms page, the layout handle company_index_index will not work. – Mohit Kumar Arora Jun 26 '18 at 11:39
  • @Arnold.M, please see my updated answer. – Mohit Kumar Arora Jun 26 '18 at 11:45
  • Still doesn't work – Arnold.M Jun 27 '18 at 7:32
  • @Arnold.M, please check my updated answer. – Mohit Kumar Arora Jun 27 '18 at 11:02

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.