Views exposed filters button HTML5 validation issues

If you care for HTML5 validation in Drupal 7, prepare to face several issues. One of these issues is having an exposed filter in a view with a submit button. The button by default has an empty name, thus not passing HTML5 validation. See the relevant issue here in the Drupal issue queue:

Empty ‘name’ value for the exposed filter submit button

Comment 4 on the previous link may do the job fine, but I only needed to just add a name in my submit button so I used a simpler version of this:

function THEME_button($variables) {
  if ($variables['element']['#id'] === 'ID-OF-MY-SUBMIT-BUTTON') {
    $variables['element']['#attributes']['name'] = 'Search';
  }
  return '<input' . drupal_attributes($variables['element']['#attributes']) . ' />';
}

Be sure to change THEME with your theme name and ID-OF-MY-SUBMIT-BUTTON with the ID of your submit button (doh!).

Leave a Reply

Your email address will not be published. Required fields are marked *