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
There is a bug when using CAPTCHA module with USWDS. When I click the "Get new captcha!" link, it does not refresh the image CAPTCHA.
Steps to reproduce
With USWDS base theme enabled
- Install CAPTCHA
- Enable CAPTCHA and Image CAPTCHA
- Enable an image CAPTCHA on any page here: /admin/config/people/captcha/captcha-points
- For example, on Drupal's built in User Log In page
- Go to the page with the CAPTCHA and poke the "Get new captcha!" link
- New captcha does not appear, page does not change
- Right click on link and open in a new tab shows that correct json data is being produced, but it just doesn't update the page
- Disable USWDS base theme and the "Get new captcha!" link works again
Comment | File | Size | Author |
---|---|---|---|
#5 | original-details.html_.twig_.txt | 1.61 KB | leraa |
#5 | fixed-details.html_.twig_.txt | 1.45 KB | leraa |
Comments
Comment #2
leraa CreditAttribution: leraa as a volunteer commentedI've discovered the problem. It is in this template:
/themes/contrib/uswds_base/templates/form/details.html.twig
If I replace the contents of this template with the same template from Bartik/Classy, it functions correctly. I'm trying to narrow down the exact breaking markup right now.
Comment #3
mferanda CreditAttribution: mferanda as a volunteer commentedThank you for your help!
Are you able to see anything specific? While I can’t really support a non core issue (using captchas), if you find a mistake with the template then we’ll definitely look at resolving. Especially if it wouldn’t cause a problem necessarily to others using this theme.
Personally, I dont use captchas with Federal sites... they’re never going to be 508 compliant. Basically then the form is no longer accessible to vision impaired.
Comment #4
leraa CreditAttribution: leraa as a volunteer commentedWell, I'm trying to find out which particular thing in that template is breaking it. I think it's the assignment of classes. I'll report back here when I'm certain.
I'm not a big fan of captchas either, but unfortunately not in a position to change their use here.
I'm starting to think that a primary problem is that the template in question is the template for the
<details>
element. It's expecting a<details>
html element to be present if the details template is used. But the USWDS template completely removes any use of the<details>
element. It takes it out and replaces it with list markup.So anything that is using the details template and expecting/needing
<details>
to be there is going to break.Comment #5
leraa CreditAttribution: leraa as a volunteer commentedI had to rip out the
<ul>
-based markup to get this to work finally.I've attached two files, the original for the convenience of comparing, and my new template with the altered markup. I had to relabel them as txt because twig files are not allowed here.
The altered markup did not require having a
<details>
element for CAPTCHA to work. That theory was wrong. But it did require the ul/li layout to be abandoned.Hope this helps.
Comment #6
mferanda CreditAttribution: mferanda as a volunteer commentedSounds like still an issue you can resolve in your own subtheme and custom the twig file.
That’ll at least resolve your issue. I’ll take a look further before moving on with 2.10 to see if i find something. Will release a beta2 if so.
Comment #7
mferanda CreditAttribution: mferanda as a volunteer commentedI'm going to have to mark this item as things working as intended. Basically, I can't see an easy path forward other than custom manipulation for a different module. This falls into something where it's not USWDS itself, but sites can adjust their own needs as necessary.
Items adjusting uswds_base should only be for Drupal Core items and/or USWDS itself.
Comment #8
mferanda CreditAttribution: mferanda as a volunteer commented