Antibot doesnt hide all form elements with JS disabled

Created on 29 January 2020, almost 5 years ago
Updated 15 June 2023, over 1 year ago

I'm seeing an issue when using a Bootstrap-based theme, where the form's top-level elements are not properly hidden when Javascript is disabled.

See before / after screenshots in first comment below.

Basically, the problem is:

1) Bootstrap overrides default Drupal form templates, removing the <div class="form-wrapper"> that is usually there.
2) A Webform places a <fieldset class="form-wrapper"> at the top level child inside the <form> element. The fieldset is styled in CSS to have a border.
2) The contents of the fieldset are hidden by way of the NOSCRIPT CSS rule that is supposed to hide all elements from antibot module, but the fieldset itself is not hidden due to it being at the top-level of the form, but the display: none only hides elements 2 levels down or below.

form.antibot * :not(.antibot-message) {
  display: none !important;
}

The fix I've found for my own theme is to add the following:


/**
 * Implements hook_page_attachments_alter().
 */
function mytheme_page_attachments_alter(array &$page) {

  // Alters the noscript style in HEAD added by antibot, to support bootstrap
  // form styles.
  foreach ($page['#attached']['html_head'] as $key => $value) {
    if (!empty($page['#attached']['html_head'][$key][1]) && $page['#attached']['html_head'][$key][1] == 'antibot_style') {
      $noscript_style = [
        '#tag' => 'style',
        '#value' => 'form.antibot .form-wrapper { display: none !important; }',
        '#noscript' => TRUE,
      ];
      $page['#attached']['html_head'][$key] = [$noscript_style, 'mytheme_antibot_style'];
    }
  }
}

I don't know offhand if this would work more widely to be adopted into the project, it needs to be tested on more standard Drupal themes like Bartik I guess.

🐛 Bug report
Status

Active

Version

2.0

Component

User interface

Created by

🇪🇨Ecuador jwilson3

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024