I built a custom form
for search filtering on my site. I'm using hidden input fields to decide what type of search filter was selected. The value gets passed and I check on my search page what the value was, and then direct to the correct search results page like so:
<?php
$search_refer = $_GET['search_type'];
if($search_refer == 'members') {
load_template(TEMPLATEPATH . '/search-members.php');
} else if($search_refer == 'event') {
load_template(TEMPLATEPATH . '/search-member-event.php');
} else {
load_template(TEMPLATEPATH . '/search-site.php');
}
?>
Here are the two fields in HTML/PHP
<div class="state"> // Sorting by user State
<input type="hidden" name="search_type" value="members">
<select id="stateDrop" name="state">
<option value="">State</option>
<?php
foreach($states as $state) {
echo '<option value="'.$state.'">'.$state.'</option>';
}
?>
</select>
</div>
<div class="sort-event"> // Sorting by an Event
<input type="hidden" name="search_type" value="event">
<select id="eventDrop" name="event">
<option value="">Event</option>
<?php
$args = array(
'post_type' => 'events',
'order' => 'ASC'
);
$eQuery = new WP_Query( $args );
while( $eQuery->have_posts() ) : $eQuery->the_post();
echo '<option value="'.$eQuery->post->post_title.'">'.$eQuery->post->post_title.'</option>';
endwhile;
wp_reset_query();
?>
</select>
</div>
Both have the name search_type
as a hidden name, but the values are different. members
vs event
. My problem is when you click on the submit button, the value being received is always the last hidden input value. e.g. event
.
Is there a way to decide which field was chosen so that I can then direct the search results to the correct page. (the search pages pull in different information based on the search).
Thanks,