HTML forms + php

Soldato
Joined
6 Apr 2008
Posts
3,352
Location
Reading
I need to have a secrch function on the front page of the software for a database project.

This search function need to be able to search 3 different databases for information.

I have already implemented the php to get the data all i need is a method of having a drop down box with the option of which type of data you are searching followed by the string you wish to search for.

The only thing is one you have selected the drop down box, this information isnt set until you submit the form, thus how does the form know which php file to send the POST data to.

I have implemented a loop back to the page but it requires an extra submit to be pressed once the data has been entered.

Is there a better way of doing this?

Code:
<?php
if (@$_POST['Selection'] == "item")
{
	echo "<form action = 'itemlist.php' method = 'POST' id = 'item'><table>";
	$bob = @$_POST['Search'];
	echo "<Input type = 'hidden' name ='Search' value = '$bob'></form>";
}
elseif (@$_POST['Selection'] == "user")
{
	echo "<form action = 'userlist.php' method = 'POST' id='user'><table>";
	$bob = @$_POST['Search'];
	echo "<Input type = 'hidden' name ='Search' value = '$bob'></form>";

}
elseif (@$_POST['Selection'] == "loan")
{
	echo "<form action = 'loanlist.php' method = 'POST' id ='loan'><table>";
	$bob = @$_POST['Search'];
	echo "<Input type = 'hidden' name ='Search' value = '$bob'></form>";
	
}
elseif (@$_POST['Selection'] == "")
{
	echo "<form action = 'main.php' method = 'POST'><table>";
	echo"<td style = width: 33%'><p>
	<span class='bold_large'><tr>";
	echo "<select name ='Selection'>";
    echo "<option value = 'item'> Item\n
    	  <option value = 'user'> User\n
    	  <option value = 'loan'> Loan\n";
    echo "</select>";
   	echo  "</td></tr>";	

	echo"<td style = width: 66%'><p>
	<span class='bold_large'>";
	echo "<tr><td><Input type = 'text' name ='Search' size = '20' maxlength='76'>";
    	  
	echo  "</td></tr>";   	  
}


?>
<tr>
<td colspan = '2' style = 'text-align: center'>
<Input type = 'submit' value = 'Search'>    	  
</td></tr></table></form>


yes its messy and far from final. your help is greatly appreciated though.

Edd
 
Well, you have a couple of options.

1) Code it with JS. You could have a little onClick event on the drop down box that dynamically changed the ACTION of the form element.
Have a google for dynamic dropdown menu or somesuch. I expect a JS library like Jquery would be helpful.
2) PHP redirect. There's no reason to have them click another submit, simply create a new php file (that the form posts to) that uses header("Location: http://www.example.com/") to redirect them to the proper page.
You'll have to put the form variables into a session or somesuch though (there may be a way to resubmit POST using php but I don't know of it offhand).
 
cheers yer i ended up using headers, didnt think id be able to but it turns out a bit of shifting around of the code and i could cram those conditionals right at the top so the header is the first thing the browser gets.

as one of the strings im passing to the next file starts with % Get cuts the first two/three char's off...... meant a whole lot of re working to verify a magnetic swipe read......

n/m job done.
 
Back
Top Bottom