studioforty9-dev / Recaptcha

Magento Module for the most recent version of Google reCAPTCHA. (This module is no longer actively supported)
BSD 3-Clause "New" or "Revised" License
50 stars 45 forks source link

ReCaptcha not displayed when contact form is added to custom block #10

Closed chris-bot-lab closed 9 years ago

chris-bot-lab commented 9 years ago

Hello,

I've installed your ReCaptcha plugin for Magento (v1.9.1) and it works well in the default contact form. However, I've created a custom block in witch I add the contact form and the ReCaptcha is not displayed at all.

I've read that doc about how to use the plugin: https://drive.google.com/file/d/0B3hRj4-KZpxMRkJEZ0JFeGNRM2c/view

Here some code to help you understand the problem:

=> my custom layout file in witch I add the Magento contact form inside my custom block

<block type="core/template" name="static-info">
    <action method="setTemplate" ifconfig="contacts/static-info/enabled" ifvalue="1">
        <template>contacts/globalcontact.phtml</template>
    </action>
    <block type="core/template" name="contactForm" template="contacts/form.phtml"/>
    <block type="newsletter/subscribe" name="newsletter" as="newsletter" template="newsletter/subscribe.phtml"/>
</block>

=> my custom template file in witch I instantiate the contact form child block

[...]
<div id="static-info-contact" class="f_right">
    <h6>Contact</h6>
    <?php echo $this->getChildHtml('contactForm'); ?>
</div>
[...]

I don't instantiate the ReCaptcha block in my custom template as it is already done in the contact form template using this line:

<?php echo $this->getChildHtml('studioforty9.recaptcha.explicit');?>

I've also tried to modify my custom layout file to manually include the ReCaptcha child element:

<block type="core/template" name="static-info">
    <action method="setTemplate" ifconfig="contacts/static-info/enabled" ifvalue="1">
        <template>contacts/globalcontact.phtml</template>
    </action>
    <block type="core/template" name="contactForm" template="contacts/form.phtml">
         <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml"/>
    </block>
    <block type="newsletter/subscribe" name="newsletter" as="newsletter" template="newsletter/subscribe.phtml"/>
</block>

Could you please tell me what I am doing wrong ?

Thank you

eoghanobrien commented 9 years ago

Hi,

It's hard to say exactly what you're doing wrong without the layout handle under which you've used your xml. But I'll give it a go.

First of all with any non standard page, you need to specifically allow the recaptcha to display using:

    <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml">
      <action method="setAllow"><value>true</value></action>
    </block>

If you're trying to use the contact form on another cms page, take a look at the new documentation, specifically the section on using recaptcha in the contact form on a different cms page. https://recaptcha.readme.io/docs/troubleshooting#section-using-recaptcha-on-the-contact-form-on-a-different-cms-page

If none of these are working for you, as a last resort you can use PHP in your template:

<?php $recaptcha = $this->getLayout()->createBlock('studioforty9_recaptcha/explicit')->setTemplate('studioforty9/recaptcha/explicit.phtml'); ?>
<?php $this->setChild('studioforty9.recaptcha.explicit', $recaptcha->setAllow(true)); ?>
<?php echo $this->getChildHtml('studioforty9.recaptcha.explicit'); ?>
chris-bot-lab commented 9 years ago

Thanks for the reply. I've added my custom block in the header block. app/design/frontend/package/default/layout/Page.xml

<?xml version="1.0"?>
<layout version="0.1.0">
<default translate="label" module="page">
    <label>All Pages</label>
    <block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml">
        [...]
        <block type="page/html_header" name="header" as="header">
            [...]
            <block type="core/template" name="static-info">
                <action method="setTemplate" ifconfig="contacts/static-info/enabled" ifvalue="1"><template>contacts/globalcontact.phtml</template></action>
                <block type="core/template" name="contactForm" template="contacts/form.phtml">
                    <block type="studioforty9_recaptcha/explicit" name="studioforty9.recaptcha.explicit" template="studioforty9/recaptcha/explicit.phtml">
                        <action method="setAllow"><value>true</value></action>
                    </block>
                </block>
                <block type="newsletter/subscribe" name="newsletter" as="newsletter" template="newsletter/subscribe.phtml"/>
            </block>
        </block>
        [...]
    </block>
</default>

I've added the code to specifically allow the recaptcha to display, but it's not working. I can't use the php code as I have to include the captcha inside the contact form, and I'm including the whole contact form block (in which I've already added the recaptcha, see 1st post) inside my custom block.

Edit: Sry I've accidentally close the issue

eoghanobrien commented 9 years ago

This is really more of a support request than an issue. Can you please email us at magento at studioforty9 dot com, just reference the URL for this issue and I'll get back to you.

chris-bot-lab commented 9 years ago

Email sent