Fixed
Project:
CAPTCHA
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 Jul 2023 at 15:29 UTC
Updated:
3 Nov 2026 at 01:17 UTC
Jump to comment: Most recent
When adding a captcha to a form by using the captcha form element, you can't simply use "default" as #captcha_type, while it would be nice to be able to do so. Currently you have to retrieve the default challenge from captcha like this:
$default_challenge = \Drupal::service('config.manager')
->getConfigFactory()
->get('captcha.settings')
->get('default_challenge');
$form['captcha'] = [
'#type' => 'captcha',
'#captcha_type' => $default_challenge,
];
For example see the famous Webform module, which has to use this code.
Allow using
$form['captcha'] = [
'#type' => 'captcha',
'#captcha_type' => 'default',
];
(or another placeholder value) and replace "default" by the default captcha type in the captcha module, before processing the element. That way other modules don't have to know about CAPTCHA modules internals.
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybodyComment #3
pbouchereau commentedHi,
The mentioned code snippet was executed in image_captcha.module file in previous versions.
It hasn't been ported to the imageCaptchaAfterBuildProcess() function in ImageCaptchaRenderService.php.
Because of this my setup partly broke when I updated.
I had "Image captcha" set as default in captcha global settings and "default" set in a captcha point for my user login form.
After updating the reload button was not displayed anymore because the image captcha type was not detected.
Comment #7
japerry