第一次发帖。我提前感谢任何帮助。我真的很感激。
我目前正在使用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 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>
答案 0 :(得分: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>