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?

  • 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
    Commented 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
    Commented Dec 13, 2021 at 18:12
  • Are you visiting the custom form anonymous?
    – Joehoe
    Commented Dec 13, 2021 at 22:05
  • how did you attached the captcha to your custom form? Commented 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
    Commented Dec 14, 2021 at 10:31

1 Answer 1


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:


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 you have read our privacy policy.

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