2017-10-12 149 views
0

首次发布。我很感激任何帮助。对此,我真的非常感激。重置/刷新WordPress主题中的搜索表单按钮

我目前使用wordpress主题来搜索世界各地的别墅,我很想添加一个重置按钮来清除字段,下拉菜单和由自定义字段应用程序填充的复选框。正常的重置按钮不起作用,因为我正在教自己的PHP在飞行中,我很茫然。这里是该页面的链接,我将粘贴一些代码,以便了解我所看到的内容。

我真的很感谢任何帮助,因为主题作者一直在吹我。

LINK

<?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>

+0

我可以看到一些JavaScript错误即将在控制台当您按下复位按钮。要清除所有表单值,我会编写一些jQuery或JavaScript代码,单击重置按钮时执行该代码。 –

回答

0

有一行代码,需要修改

<a href="javascript:document.getElementById('form_[form_key]').reset();" autocomplete="off">Reset Form</a> 

该元素不存在,形式有一个名为property-search-form,你可以使用类作为选择器。

所以的东西代替线像

<a href="javascript:document.getElementsByClassName('property-search-form').reset();" autocomplete="off">Reset Form</a> 
+0

谢谢安德鲁。欣赏回应。现在我只需要让JavaScript运行。我从未编辑过这么多的主题。 – eyetrip

+0

不是非常理想的编辑主题,因为任何更新都会覆盖您的修改。 –