diff --git a/core/includes/form.inc b/core/includes/form.inc index a3d17a7f29fff15d4db4eec5da7a46af4df3cef3..58563c60b4a1b8753248ba5405cf01f2feb0edbd 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -325,6 +325,10 @@ function template_preprocess_vertical_tabs(&$variables) { */ function template_preprocess_input(&$variables) { $element = $variables['element']; + // Remove name attribute if empty, for W3C compliance. + if (isset($variables['attributes']['name']) && empty((string) $variables['attributes']['name'])) { + unset($variables['attributes']['name']); + } $variables['children'] = $element['#children']; } diff --git a/core/modules/search/src/Tests/SearchBlockTest.php b/core/modules/search/src/Tests/SearchBlockTest.php index 8351878e22acab8cd1f120ab22eb4c618c327f35..54065020b77dc50e6f01a96ae739a6739d44e482 100644 --- a/core/modules/search/src/Tests/SearchBlockTest.php +++ b/core/modules/search/src/Tests/SearchBlockTest.php @@ -45,6 +45,11 @@ public function testSearchFormBlock() { $this->drupalGet(''); $this->assertText($block->label(), 'Block title was found.'); + // Check that name attribute is not empty. + $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('keys' => 'test'); $this->submitGetForm('', $terms, t('Search'));