Click to See Complete Forum and Search --> : PHP filter form


bp_travis
10-01-2007, 04:07 PM
Hello. I have what seems like a simple need, but it seems to be getting complex. I have a site that displays results of certain critiria and I want a form at the top of the page that is able to filter the results. Problem is, that the first criteria that is given to the PHP is a $GET from the address bar, while the form at the top is a $POST. When I try to do it, it displays the info from the $POST and the $GET. Here is a simplified version of the PHP. Thanks

if(isset($_POST)){
$show=$_POST['show'];
if ($show=='gke'){
echo $show;
}

}
if (isset($_GET)){
$show=$_GET['show'];
echo $show;

}



<form action="" method="post" name="show">
Filter By:<br />
Show:
<select name="show" id="show" onchange=document.show.submit();>
<option selected value="ge">Groom Expo</option>
<option value="gke">GKE</option>

</select>
Breed:
<select name="select">
<option value="Poodle" selected="selected">Poodle</option>
<option value="Terrier">Terrier</option>
<option value="Spaniel">Spaniel</option>
</select>
</form>

valenok
10-01-2007, 04:37 PM
$q = '';
foreach ($_GET as $key => $val)
$q.= $key . "=" .$val . "&" ;

...

<form method='post' action='?<?=$q?>'>

NightShift58
10-02-2007, 12:29 AM
IF (isset($_POST['show'])) :
$show=$_POST['show'];
IF ($show=='gke') :
echo $show;
ENDIF;
ELSEIF (isset($_GET['show'])) :
$show=$_GET['show'];
echo $show;
ENDIF;


I think that you need to be more specific when you check for the existence of POST or GET variables and not just check on the existence of $_POST and $_GET.

The way you're code was structured, it ran through both IF because both were positive.