In the HTML outputted from get_search_form(): increment the ID connecting <label> to <input> when the function is called multiple times, remove the form and submit button IDs for HTML 5.0 and for XHTML after the first call. Props WraithKenny, fixes #16539

git-svn-id: http://core.svn.wordpress.org/trunk@23801 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2013-03-26 23:18:43 +00:00
parent ae48aed870
commit edb3712956
1 changed files with 27 additions and 10 deletions

View File

@ -153,32 +153,49 @@ function get_template_part( $slug, $name = null ) {
* @return string|null String when retrieving, null when displaying or if searchform.php exists. * @return string|null String when retrieving, null when displaying or if searchform.php exists.
*/ */
function get_search_form( $echo = true ) { function get_search_form( $echo = true ) {
static $search_form_counter = 0;
do_action( 'pre_get_search_form' ); do_action( 'pre_get_search_form' );
$format = apply_filters( 'search_form_format', 'xhtml' ); $format = apply_filters( 'search_form_format', 'xhtml' );
// Initialize the values
$form_id = $search_form_counter ? '' : ' id="searchform"';
$submit_id = $search_form_counter ? '' : ' id="searchsubmit"';
$text_id = $search_form_counter ? 's-' . $search_form_counter : 's';
$search_form_template = locate_template( 'searchform.php' ); $search_form_template = locate_template( 'searchform.php' );
if ( '' != $search_form_template ) { if ( '' != $search_form_template ) {
ob_start(); ob_start();
require( $search_form_template ); require( $search_form_template );
$form = ob_get_clean(); $form = ob_get_clean();
} else { } else {
$type = ( 'html5' === $format ) ? 'search' : 'text'; if ( 'html5' == $format ) {
$placeholder = ( 'html5' === $format ) ? 'placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" ' : ''; $form = '<form role="search" method="get" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
<div>
$form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '"> <label><span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
<div> <input type="search" placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . _x( 'Search for:', 'label' ) . '" />
<label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label> </label>
<input type="' . $type . '" ' . $placeholder . 'value="' . get_search_query() . '" name="s" id="s" /> <input type="submit" class="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
<input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" /> </div>
</div> </form>';
</form>'; } else {
$form = '<form role="search" method="get"' . $form_id . ' class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
<div>
<label class="screen-reader-text" for="' . $text_id . '">' . _x( 'Search for:', 'label' ) . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="' . $text_id . '" />
<input type="submit"' . $submit_id . ' value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
</div>
</form>';
}
} }
$result = apply_filters( 'get_search_form', $form ); $result = apply_filters( 'get_search_form', $form );
if ( null === $result ) if ( null === $result )
$result = $form; $result = $form;
$search_form_counter++;
if ( $echo ) if ( $echo )
echo $result; echo $result;
else else