首次發佈。我很感激任何幫助。對此,我真的非常感激。重置/刷新WordPress主題中的搜索表單按鈕
我目前使用wordpress主題來搜索世界各地的別墅,我很想添加一個重置按鈕來清除字段,下拉菜單和由自定義字段應用程序填充的複選框。正常的重置按鈕不起作用,因爲我正在教自己的PHP在飛行中,我很茫然。這裏是該頁面的鏈接,我將粘貼一些代碼,以便了解我所看到的內容。
我真的很感謝任何幫助,因爲主題作者一直在吹我。
<?php
\t 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()); } ?>">
\t <div class="row">
\t \t <?php if (isset($realty_theme_option['property-search-results-page']) && empty($realty_theme_option['property-search-results-page'])) { ?>
\t \t \t <div class="col-xs-12" style="margin-bottom: 1em">
\t \t \t \t <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>
\t \t \t </div>
\t \t <?php } ?>
\t \t <?php
\t \t \t // Form select classes
\t \t \t $form_select_class = 'form-control';
\t \t \t if ($realty_theme_option['enable-rtl-support'] || is_rtl()) {
\t \t \t \t $form_select_class .= ' chosen-select chosen-rtl';
\t \t \t } else {
\t \t \t \t $form_select_class .= ' chosen-select';
\t \t \t }
\t \t \t $acf_field_array = array();
\t \t \t if (isset($realty_theme_option['property-search-features']) && ! tt_is_array_empty($realty_theme_option['property-search-features'])) {
\t \t $property_search_features = $realty_theme_option['property-search-features'];
\t \t \t } else {
\t \t \t \t $property_search_features = null;
\t \t \t }
\t \t \t $raw_search_params = get_query_var('property_search_parameters');
\t \t \t if (! tt_is_array_empty($raw_search_params)) {
\t \t \t \t $search_parameters = $raw_search_params;
\t \t \t } else if (isset($realty_theme_option['property-search-parameter']) && ! empty($realty_theme_option['property-search-parameter'])) {
\t \t \t \t $search_parameters = $realty_theme_option['property-search-parameter'];
\t \t \t } else {
\t \t \t \t $search_parameters = null;
\t \t \t }
\t \t \t $raw_search_fields = get_query_var('property_search_fields');
\t \t \t if (! tt_is_array_empty($raw_search_fields)) {
\t \t \t \t $search_fields = $raw_search_fields;
\t \t \t } else if (isset($realty_theme_option['property-search-parameter']) && ! empty($realty_theme_option['property-search-parameter'])) {
\t \t \t \t $search_fields = $realty_theme_option['property-search-field'];
\t \t \t } else {
\t \t \t \t $search_fields = null;
\t \t \t }
\t \t \t $raw_search_labels = get_query_var('property_search_labels');
\t \t \t if (! tt_is_array_empty($raw_search_labels)) {
\t \t \t \t $search_labels = $raw_search_labels;
\t \t \t } else if (isset($realty_theme_option['property-search-label']) && ! empty($realty_theme_option['property-search-label'])) {
\t \t \t \t $search_labels = $realty_theme_option['property-search-label'];
\t \t \t } else {
\t \t \t \t $search_labels = null;
\t \t \t }
\t \t \t $default_search_fields_array = array(
\t \t \t \t 'estate_search_by_keyword',
\t \t \t \t 'estate_property_id',
\t \t \t \t 'estate_property_location',
\t \t \t \t 'estate_property_type',
\t \t \t \t 'estate_property_status',
\t \t \t \t 'estate_property_price',
\t \t \t \t 'estate_property_price_min',
\t \t \t \t 'estate_property_price_max',
\t \t \t \t 'estate_property_pricerange',
\t \t \t \t 'estate_property_size',
\t \t \t \t 'estate_property_rooms',
\t \t \t \t 'estate_property_bedrooms',
\t \t \t \t 'estate_property_bathrooms',
\t \t \t \t 'estate_property_garages',
\t \t \t \t 'estate_property_available_from'
\t \t \t);
\t \t \t $i = 0;
\t \t \t if (isset($search_form_columns) && ! empty($search_form_columns)) {
\t \t \t \t // Use $columns parameter from shortcode [property_search_form]
\t \t \t \t $count_search_fields = $search_form_columns;
\t \t \t } else {
\t \t \t \t // No shortcode $columns found, pick columns according to total field count
\t \t \t \t $count_search_fields = count($search_fields);
\t \t \t }
\t \t \t if ($count_search_fields == 1) {
\t \t \t \t $columns = 'col-xs-12';
\t \t \t } else if ($count_search_fields == 2) {
\t \t \t \t $columns = 'col-xs-12 col-sm-6';
\t \t \t } else if ($count_search_fields == 3) {
\t \t \t \t $columns = 'col-xs-12 col-sm-6 col-md-4';
\t \t \t } else {
\t \t \t \t $columns = 'col-xs-12 col-sm-4 col-md-3';
\t \t \t }
\t \t \t if (is_page_template('template-map-vertical.php')) {
\t \t \t \t $columns = 'col-xs-12 col-sm-6';
\t \t \t }
\t \t \t // Do we have any search parameters defined?
\t \t \t if (isset($search_parameters) && ! empty($search_parameters[0])) {
\t \t \t \t foreach ($search_fields as $search_field) {
\t \t \t \t \t $search_parameter = $search_parameters[$i];
\t \t \t \t \t // Check If Search Field Is Filled Out
\t \t \t \t \t if (! empty($search_field)) {
\t \t \t \t \t \t // Default Property Field
\t \t \t \t \t \t if (in_array($search_field, $default_search_fields_array)) {
\t \t \t \t \t \t \t switch ($search_field) {
\t \t \t \t \t \t \t \t case 'estate_search_by_keyword' :
\t \t \t \t \t \t \t \t case 'estate_property_id' :
\t \t \t \t \t \t \t \t ?>
\t \t \t \t \t \t \t \t <div class="<?php echo $columns; ?> form-group">
\t \t \t \t \t \t \t \t \t <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" />
\t \t \t \t \t \t \t \t </div>
\t \t \t \t \t \t \t \t <?php
\t \t \t \t \t \t \t \t break;
\t \t \t \t \t \t \t \t case 'estate_property_location' : ?>
\t \t \t \t \t \t \t \t <div class="<?php echo $columns; ?> form-group select">
\t \t \t \t \t \t \t \t \t <?php
\t \t \t \t \t \t \t \t \t \t // http://wordpress.stackexchange.com/questions/14652/how-to-show-a-hierarchical-terms-list#answer-14658
\t \t \t \t \t \t \t \t \t \t if (! empty($search_labels[$i])) {
\t \t \t \t \t \t \t \t \t \t \t $search_label_location = $search_labels[$i];
\t \t \t \t \t \t \t \t \t \t } else {
\t \t \t \t \t \t \t \t \t \t \t $search_label_location = esc_html__('Any Location', 'realty');
\t \t \t \t \t \t \t \t \t \t }
\t \t \t \t \t \t \t \t \t ?>
\t \t \t \t \t \t \t \t \t <select name="<?php echo $search_parameter; ?>" id="<?php echo $search_parameter; ?>" class="<?php echo esc_attr($form_select_class); ?>">
\t \t \t \t \t \t \t \t \t \t <option value="all"><?php echo $search_label_location; ?></option>
\t \t \t \t \t \t \t \t <?php
\t \t \t \t \t \t \t \t \t $location = get_terms('property-location', array(
\t \t \t \t \t \t \t \t \t \t 'orderby' => 'slug',
\t \t \t \t \t \t \t \t \t \t 'parent' => 0,
\t \t \t \t \t \t \t \t \t \t 'hide_empty' => false
\t \t \t \t \t \t \t \t \t ));
\t \t \t \t \t \t \t \t \t if (isset($_GET[$search_parameter])) {
\t \t \t \t \t \t \t \t \t \t \t \t $get_location = $_GET[$search_parameter];
\t \t \t \t \t \t \t \t \t \t \t } else {
\t \t \t \t \t \t \t \t \t \t \t \t $get_location = null;
\t \t \t \t \t \t \t \t \t \t \t }
\t \t \t \t \t \t \t \t \t \t ?>
\t \t \t \t \t \t \t \t <?php foreach ($location as $key => $location) : ?>
\t \t \t \t \t \t <option value="<?php echo $location->slug; ?>" <?php selected($location->slug, $get_location); ?>>
\t \t \t \t \t <?php
\t \t \t \t \t \t echo $location->name;
\t \t \t \t \t \t $location2 = get_terms('property-location', array(
\t \t \t \t \t \t \t 'orderby' => 'slug',
\t \t \t \t \t \t \t 'parent' => $location->term_id
\t \t \t \t \t \t ));
\t \t \t \t \t \t if ($location2) :
\t \t \t \t \t ?>
\t \t \t \t \t <optgroup>
\t \t \t \t \t <?php foreach($location2 as $key => $location2) : ?>
\t \t \t \t \t <option value="<?php echo $location2->slug; ?>" class="level2" <?php selected($location2->slug, $get_location); ?>>
\t \t \t \t \t \t <?php
\t \t \t \t \t \t \t echo $location2->name;
\t \t \t \t \t \t \t $location3 = get_terms('property-location', array(
\t \t \t \t \t \t \t \t 'orderby' => 'slug',
\t \t \t \t \t \t \t \t 'parent' => $location2->term_id
\t \t \t \t \t \t \t));
\t \t \t \t \t \t \t if ($location3) :
\t \t \t \t \t \t ?>
\t \t \t \t \t \t <optgroup>
\t \t \t \t \t \t \t <?php foreach($location3 as $key => $location3) : ?>
\t \t \t \t \t \t \t <option value="<?php echo $location3->slug; ?>" class="level3" <?php selected($location3->slug, $get_location); ?>>
\t \t \t \t \t \t \t <?php
\t \t \t \t \t \t \t echo $location3->name;
\t \t \t \t \t \t \t $location4 = get_terms('property-location', array('orderby' => 'slug', 'parent' => $location3->term_id));
\t \t \t \t \t \t \t if($location4) :
\t \t \t \t \t \t \t ?>
\t \t \t \t \t \t \t <optgroup>
\t \t \t \t \t \t \t \t <?php foreach($location4 as $key => $location4) : ?>
\t \t \t \t \t \t \t \t <option value="<?php echo $location4->slug; ?>" class="level4" <?php selected($location4->slug, $get_location); ?>>
\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t <?php echo $location4->name; ?>
\t \t \t \t \t \t \t \t </option>
\t \t \t \t \t \t \t \t <?php endforeach; ?>
\t \t \t \t \t \t \t </optgroup>
\t \t \t \t \t \t \t <?php endif; ?>
\t \t \t \t \t \t \t </option>
\t \t \t \t \t \t \t <?php endforeach; ?>
\t \t \t \t \t \t </optgroup>
\t \t \t \t \t \t <?php endif; ?>
\t \t \t \t \t </option>
\t \t \t \t \t <?php endforeach; ?>
\t \t \t \t \t </optgroup>
\t \t \t \t \t <?php endif; ?>
\t \t \t \t \t \t </option>
\t \t \t \t \t \t \t \t <?php endforeach; ?>
\t \t \t \t \t \t \t \t \t </select>
\t \t \t \t \t \t \t \t </div>
我可以看到一些JavaScript錯誤即將在控制檯當您按下復位按鈕。要清除所有表單值,我會編寫一些jQuery或JavaScript代碼,單擊重置按鈕時執行該代碼。 –