Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
My webform contains a CAPTCHA element that I wanted to disable temporarily. Adding a custom setting, setting #access to FALSE, does hide the form element. However the validation is not disabled, so submitting the form results in the error message "The answer you entered for the CAPTCHA was not correct."
The form:
tagline: '#type': webform_markup '#markup': '<h3>Subscribe to the newsletter</h3>' email: '#title': Email '#placeholder': Email '#type': email '#required': true cacptcha: '#type': captcha '#title': Captcha '#captcha_type': recaptcha/reCAPTCHA '#access': false actions: '#type': webform_actions '#title': 'Submit button(s)' '#submit__label': Subscribe
Proposed resolution
Do not validate elements with #access=FALSE.
Comment | File | Size | Author |
---|---|---|---|
#5 | bypass_captcha_validation_access_false_1.patch | 1.79 KB | sonvir249 |
| |||
#3 | bypass_captcha_validation_access_false.patch | 1.79 KB | sonvir249 |
|
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe CAPTCHA module would have to update the captcha_validate to address this issue.
If the CAPTCHA module did ignore elements with #access: false, this might make it possible to include a CAPTCHA on a multistep webform.
I am going to move this issue to the CAPTCHA module's issue queue.
Comment #3
sonvir249 CreditAttribution: sonvir249 as a volunteer and at QED42 commentedI have added a new access form element in CAPTCHA form elements.
Then i am validating access element in captcha_validate .
Thank you.
Comment #4
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedPlease break the comment line as it exceeds the limit.
Comment #5
sonvir249 CreditAttribution: sonvir249 as a volunteer and at QED42 commentedHi @gg24
Changes done as suggested.
Thank you.
Comment #6
gg24 CreditAttribution: gg24 as a volunteer and at QED42 commentedHi @sonvir249,
I have reviewed the patch mentioned above and able to apply it cleanly and works as intended.
Steps followed :-
Hence patch works perfectly fine.
Thanks!
Comment #8
elachlan CreditAttribution: elachlan commented