WordPress : Bouton Réinitialiser/Actualiser le formulaire de recherche dans le thème WordPress
Première publication. J’apprécie toute aide à l’avance. J’apprécie vraiment cela.
Je travaille actuellement avec un thème wordpress pour rechercher des villas dans le monde entier et j’aimerais ajouter un bouton de réinitialisation qui effacerait les champs, les listes déroulantes et les cases à cocher remplies par une application de champs personnalisés. Le bouton de réinitialisation normal ne fonctionne pas et depuis que j’apprends PHP à la volée, je suis perdu. Voici le lien vers la page et je vais coller une partie du code pour que vous ayez une idée de ce que je regarde.
J’apprécie vraiment toute aide puisque l’auteur du thème m’a bluffé.
LIEN
<?php
global $realty_theme_option, $wp_query;
?>
<form class="property-search-form border-box" action="<?php if ( tt_page_id_template_search() ) { echo get_permalink( tt_page_id_template_search() ); } ?>">
<div class="row">
<?php if ( isset( $realty_theme_option['property-search-results-page'] ) && empty( $realty_theme_option['property-search-results-page'] ) ) { ?>
<div class="col-xs-12" style="margin-bottom: 1em">
<p class="alert alert-info"><?php esc_html_e( 'Please go to "Appearance > Theme Options > Pages" and set the page you want to use as your property search results.', 'realty' ); ?></p>
</div>
<?php } ?>
<?php
// Form select classes
$form_select_class = 'form-control';
if ( $realty_theme_option['enable-rtl-support'] || is_rtl() ) {
$form_select_class .= ' chosen-select chosen-rtl';
} else {
$form_select_class .= ' chosen-select';
}
$acf_field_array = array();
if ( isset( $realty_theme_option['property-search-features'] ) && ! tt_is_array_empty( $realty_theme_option['property-search-features'] ) ) {
$property_search_features = $realty_theme_option['property-search-features'];
} else {
$property_search_features = null;
}
$raw_search_params = get_query_var( 'property_search_parameters' );
if ( ! tt_is_array_empty( $raw_search_params ) ) {
$search_parameters = $raw_search_params;
} else if ( isset( $realty_theme_option['property-search-parameter'] ) && ! empty( $realty_theme_option['property-search-parameter'] ) ) {
$search_parameters = $realty_theme_option['property-search-parameter'];
} else {
$search_parameters = null;
}
$raw_search_fields = get_query_var('property_search_fields');
if ( ! tt_is_array_empty( $raw_search_fields ) ) {
$search_fields = $raw_search_fields;
} else if ( isset( $realty_theme_option['property-search-parameter'] ) && ! empty( $realty_theme_option['property-search-parameter'] ) ) {
$search_fields = $realty_theme_option['property-search-field'];
} else {
$search_fields = null;
}
$raw_search_labels = get_query_var('property_search_labels');
if ( ! tt_is_array_empty( $raw_search_labels ) ) {
$search_labels = $raw_search_labels;
} else if ( isset( $realty_theme_option['property-search-label'] ) && ! empty( $realty_theme_option['property-search-label'] ) ) {
$search_labels = $realty_theme_option['property-search-label'];
} else {
$search_labels = null;
}
$default_search_fields_array = array(
'estate_search_by_keyword',
'estate_property_id',
'estate_property_location',
'estate_property_type',
'estate_property_status',
'estate_property_price',
'estate_property_price_min',
'estate_property_price_max',
'estate_property_pricerange',
'estate_property_size',
'estate_property_rooms',
'estate_property_bedrooms',
'estate_property_bathrooms',
'estate_property_garages',
'estate_property_available_from'
);
$i = 0;
if ( isset( $search_form_columns ) && ! empty( $search_form_columns ) ) {
// Use $columns parameter from shortcode [property_search_form]
$count_search_fields = $search_form_columns;
} else {
// No shortcode $columns found, pick columns according to total field count
$count_search_fields = count( $search_fields );
}
if ( $count_search_fields == 1 ) {
$columns = 'col-xs-12';
} else if ( $count_search_fields == 2 ) {
$columns = 'col-xs-12 col-sm-6';
} else if ( $count_search_fields == 3 ) {
$columns = 'col-xs-12 col-sm-6 col-md-4';
} else {
$columns = 'col-xs-12 col-sm-4 col-md-3';
}
if ( is_page_template( 'template-map-vertical.php' ) ) {
$columns = 'col-xs-12 col-sm-6';
}
// Do we have any search parameters defined?
if ( isset( $search_parameters ) && ! empty( $search_parameters[0] ) ) {
foreach ( $search_fields as $search_field ) {
$search_parameter = $search_parameters[$i];
// Check If Search Field Is Filled Out
if ( ! empty( $search_field ) ) {
// Default Property Field
if ( in_array( $search_field, $default_search_fields_array ) ) {
switch ( $search_field ) {
case 'estate_search_by_keyword' :
case 'estate_property_id' :
?>
<div class="<?php echo $columns; ?> form-group">
<input type="text" name="<?php echo $search_parameter; ?>" id="<?php echo $search_parameter; ?>" value="<?php echo isset( $_GET[$search_parameter]) ? $_GET[$search_parameter] : ''; ?>" placeholder="<?php echo $search_labels[$i]; ?>" class="form-control" />
</div>
<?php
break;
case 'estate_property_location' : ?>
<div class="<?php echo $columns; ?> form-group select">
<?php
// http://wordpress.stackexchange.com/questions/14652/how-to-show-a-hierarchical-terms-list#answer-14658
if ( ! empty( $search_labels[$i] ) ) {
$search_label_location = $search_labels[$i];
} else {
$search_label_location = esc_html__( 'Any Location', 'realty' );
}
?>
<select name="<?php echo $search_parameter; ?>" id="<?php echo $search_parameter; ?>" class="<?php echo esc_attr( $form_select_class ); ?>">
<option value="all"><?php echo $search_label_location; ?></option>
<?php
$location = get_terms('property-location', array(
'orderby' => 'slug',
'parent' => 0,
'hide_empty' => false
) );
if ( isset( $_GET[$search_parameter] ) ) {
$get_location = $_GET[$search_parameter];
} else {
$get_location = null;
}
?>
<?php foreach ( $location as $key => $location ) : ?>
<option value="<?php echo $location->slug; ?>" <?php selected( $location->slug, $get_location ); ?>>
<?php
echo $location->name;
$location2 = get_terms( 'property-location', array(
'orderby' => 'slug',
'parent' => $location->term_id
) );
if ( $location2 ) :
?>
<optgroup>
<?php foreach( $location2 as $key => $location2 ) : ?>
<option value="<?php echo $location2->slug; ?>" class="level2" <?php selected( $location2->slug, $get_location ); ?>>
<?php
echo $location2->name;
$location3 = get_terms( 'property-location', array(
'orderby' => 'slug',
'parent' => $location2->term_id
) );
if ( $location3 ) :
?>
<optgroup>
<?php foreach( $location3 as $key => $location3 ) : ?>
<option value="<?php echo $location3->slug; ?>" class="level3" <?php selected( $location3->slug, $get_location ); ?>>
<?php
echo $location3->name;
$location4 = get_terms( 'property-location', array( 'orderby' => 'slug', 'parent' => $location3->term_id ) );
if( $location4 ) :
?>
<optgroup>
<?php foreach( $location4 as $key => $location4 ) : ?>
<option value="<?php echo $location4->slug; ?>" class="level4" <?php selected( $location4->slug, $get_location ); ?>>
<?php echo $location4->name; ?>
</option>
<?php endforeach; ?>
</optgroup>
<?php endif; ?>
</option>
<?php endforeach; ?>
</optgroup>
<?php endif; ?>
</option>
<?php endforeach; ?>
</optgroup>
<?php endif; ?>
</option>
<?php endforeach; ?>
</select>
</div>
Solution n°1 trouvée
Il y a une ligne de code qui doit être modifiée
<a href="javascript:document.getElementById('form_[form_key]').reset();" autocomplete="off">Reset Form</a>
Cet élément n’existe pas, le formulaire a une classe appelée property-search-form
que vous pouvez utiliser comme sélecteur.
Remplacez donc la ligne par quelque chose comme
<a href="javascript:document.getElementsByClassName('property-search-form').reset();" autocomplete="off">Reset Form</a>
0 commentaire