diff --git a/includes/form.inc b/includes/form.inc index baadcef..4635cf2 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -3911,6 +3911,11 @@ function theme_button($variables) { $element['#attributes']['type'] = 'submit'; element_set_attributes($element, array('id', 'name', 'value')); + // Remove name attribute if empty, for W3C compliance. + if (isset($element['#attributes']['name']) && $element['#attributes']['name'] === '') { + unset($element['#attributes']['name']); + } + $element['#attributes']['class'][] = 'form-' . $element['#button_type']; if (!empty($element['#attributes']['disabled'])) { $element['#attributes']['class'][] = 'form-button-disabled'; diff --git a/modules/search/search.test b/modules/search/search.test index 913d198..2d34200 100644 --- a/modules/search/search.test +++ b/modules/search/search.test @@ -630,6 +630,12 @@ class SearchBlockTestCase extends DrupalWebTestCase { $edit = array('blocks[search_form][region]' => 'content'); $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + // Check that name attribute is not empty. + $this->drupalGet(''); + $pattern = "//input[@type='submit' and @name='']"; + $elements = $this->xpath($pattern); + $this->assertTrue(empty($elements), 'The search input field does not have empty name attribute.'); + // Test a normal search via the block form, from the front page. $terms = array('search_block_form' => 'test'); $this->drupalPost('node', $terms, t('Search'));