10

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?

22

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.

  • 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... – Malaiselvan Jan 16 '16 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 '16 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. – Malaiselvan Jan 17 '16 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 – Ankit Shah Aug 30 '16 at 4:20
  • I want to use default captcha in newsletter form. so which kind of changes i shall make ? – Sarfaraj Sipai Aug 27 '18 at 4:54
0

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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.