cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to call captcha of conatct form on another cms page

Unable to call captcha of conatct form on another cms page

Hello,

 

Captcha is visible to my default contact us page, https://domain.com/contact/. 

 

But whenever i tried to call it on another cms page, captcha is not visible.

 

{{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}

 

I am using above given code to call contact us form in another page. Please help me if i am doing anything wrong. I just want to enable captcha in my cms page where I call contact us form.

 

Thanks,

Himanshi Gupta

2 REPLIES 2

Re: Unable to call captcha of conatct form on another cms page

I'm afraid it's not quite as simple as that. Captcha is a separate module with its own block https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Captcha/Block/Captcha.php

 

The captcha module then specifically observes that pages that it wishes to protect and adds a check in for the correct captcha on that form: 

 

https://github.com/magento/magento2/tree/2.2-develop/app/code/Magento/Captcha/Observer

 

The event observer for the regular contact form is set up here: https://github.com/magento/magento2/blob/9c14af7a97bcf338662de365d2613c7ca9dbf8c6/app/code/Magento/C...

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

Re: Unable to call captcha of conatct form on another cms page

There is a solution for inserting also the specific reCaptcha as a block.

Here the example for the reCaptcha on the register-page:

 

echo $this->getLayout()
    ->createBlock('MSP\ReCaptcha\Block\Frontend\ReCaptcha',
        'msp-recaptcha',
        ['data' =>
            [
                'jsLayout' =>
                    [
                        'components' =>
                            [
                                'msp-recaptcha' =>
                                    [
                                        'component' => 'MSP_ReCaptcha/js/reCaptcha',
                                        'reCaptchaId' => 'msp-recaptcha',
                                        'zone' => 'create'
                                    ]
                            ]
                    ]
            ]
        ]
    )
    ->setTemplate('MSP_ReCaptcha::msp_recaptcha.phtml')
    ->toHtml();