13

I use the below code in a CMS block to show the default magento contact us form.

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

Just wondering will there be a core way to enable captcha in the form?

1

2 Answers 2

27

In order to add CAPTHA to a Contact Us form you have to go to Stores -> Configuration -> Customers -> Customers Configuration page and Enable CAPTCHA. Make sure to select Contact Us value in Forms field.

enter image description here

Once you update configuration, clean cache.

Hope it helps.

7
  • I believe the design Tab is only for page and not for the block. Also the question I asked is how to show Captcha on the contact Us form which I dont believe you answer addresses that... Jan 16, 2016 at 17:33
  • @Malaiselvan i completely missed the whole point of the question. It was long day yesterday. Let me write you an answer.
    – Max Pronko
    Jan 16, 2016 at 18:46
  • Thanks. You are correct. However I realized that I do not need to create a block or a page for contact us. All I need to do is enable Contact Us from Configuration and enable Catpcha for Contact Us. Jan 17, 2016 at 14:25
  • 3
    Suppose i have created Custom Form & i want to add that in "Forms" list then how can i manage this?. So on my custom form also captcha will display
    – Jackson
    Aug 30, 2016 at 4:20
  • I want to use default captcha in newsletter form. so which kind of changes i shall make ? Aug 27, 2018 at 4:54
5

You can make a custom form template (based on the original) then you can load reCaptcha block programmatically whith this :

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

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.