0

Our website has a custom route, with a controller rendering a custom Webform. This is required, as the form has some hidden fields to be pre-populated.

Now I would like to add the CAPTCHA module to the webform. When enabling the CAPTCHA for Drupal's default contact form and viewing it in incognito mode, it works nicely. The CAPTCHA shows up.

But when adding the CAPTCHA element to the custom form, it is not displayed at all.

I've tried several ways to embed the form, but none is working:

  • Embed as a Webform entity (using getSubmissionForm(..))
  • Embed as a Webform entity (using getViewBuilder('webform'))
  • Embed as a render array with the new element type webform

Would be glad to get any info on what's wrong here?

6
  • Are there any JS errors in console? Is the element rendered on the page, but not visible (i.e. in the HTML source)? Does the CAPTCHA display when you render the webform normally, and only fails on your custom route when you render the webform programmatically?
    – sonfd
    Dec 13, 2021 at 15:36
  • @sonfd nope, no JS errors. There is also nothing CAPTCHA related in the HTML source. I'm quite sure the problem is on the Drupal /backend-side. Now, I've also created a standard page which includes the webform. And no, de CAPTCHA doesn't display there either. When selecting the standard contact form instead, it works.
    – david
    Dec 13, 2021 at 18:12
  • Are you visiting the custom form anonymous?
    – Joehoe
    Dec 13, 2021 at 22:05
  • how did you attached the captcha to your custom form? Dec 14, 2021 at 5:05
  • @Joehoe yes, see above in my question - I'm viewing it in "incognito mode". The standard contact form works this way, the custom one not.
    – david
    Dec 14, 2021 at 10:31

1 Answer 1

0

It turned out there is a custom twig template in the theme, specifically overwriting this form only. In this template only some specific form elements are rendered:

/web/themes/custom/some_theme/templates/webfom/webform--course-registration.html.twig

This wasn't visible at first, because other templates related to this custom form implementation are located in the custom form module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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