第一次发布。非常感谢你提前提供的帮助。我真的很感激。
【WordPress主题中的重置/刷新搜索表单按钮】我目前正在使用wordpress主题来搜索世界各地的别墅, 并且我想添加一个重置按钮, 以清除由自定义字段应用填充的字段, 下拉列表和复选框。正常的重置按钮不起作用, 由于我正在自己动手自学PHP, 所以我很茫然。这是指向页面的链接, 我将粘贴一些代码, 以便你了解我正在查看的内容。
我非常感谢任何帮助, 因为主题作者一直让我失望。
链接
<
?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 Outif ( ! empty( $search_field ) ) {// Default Property Fieldif ( 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="http://www.srcmini.com/<
?php echo isset( $_GET[$search_parameter]) ? $_GET[$search_parameter] :'';
?>
" placeholder="<
?php echo $search_labels[$i];
?>
" class="form-control" />
<
/div>
<
?phpbreak;
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-14658if ( ! 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="http://www.srcmini.com/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="http://www.srcmini.com/<
?php echo $location->
slug;
?>" <
?php selected( $location->
slug, $get_location );
?>
>
<
?phpecho $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="http://www.srcmini.com/<
?php echo $location2->
slug;
?>" class="level2" <
?php selected( $location2->
slug, $get_location );
?>
>
<
?phpecho $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="http://www.srcmini.com/<
?php echo $location3->
slug;
?>" class="level3" <
?php selected( $location3->
slug, $get_location );
?>
>
<
?phpecho $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="http://www.srcmini.com/<
?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>
#1有一行代码需要修改
<
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>
推荐阅读
- 从WordPress中删除列的填充
- 在WordPress管理员中替换user-edit.php页面
- 在免费的wordpress主题中对section进行重新排序
- 在macOS的Safari上删除正文行右侧的不需要的白色填充
- 当容器= false时删除WordPress包装器Div失败
- Zabbix latest.php SQL注入漏洞(CVE-2016-10134)
- 基于STM32的IAP升级程序
- 路由基础之RIP的水平分割及触发更新
- Oracle Data Guard系列(单机环境基于拷贝文件方式搭建DG)