...

View Full Version : Form Problem



ojsimon
03-04-2008, 08:12 PM
Hi
I am making a search form that returns the word that the user searched as an experiment, this is the code i am using on index.html

<html>
<body>


<center><form action="welcome.php" method="post">
<input type="text" size="40" name="name" /></center>

<center><input type="submit" value="Search" /></center>
</form>

</html>

Then for the second page welcome.php i am using

<?php echo $_POST["name"]; ?>

What i want is firstly for what the user searches to be in the url for example in a google search for php http://www.google.co.uk/search?hl=en&q=php&btnG=Google+Search&meta= php is in the url how can i make mine so it is /search?PHP for example?

Also how can i make it so on the second page the search box is there?

Thanks

twomt
03-04-2008, 08:26 PM
What i want is firstly for what the user searches to be in the url for example in a google search for php http://www.google.co.uk/search?hl=en&q=php&btnG=Google+Search&meta= php is in the url how can i make mine so it is /search?PHP for example?

You mean like this?


<?php
$search = $_POST["name"];
echo ("<a href=\"http://www.google.co.uk/search?$search\">http://www.google.co.uk/search?$search</a>");
?>


Also how can i make it so on the second page the search box is there?

Don't redirect to a new page but put the php code on in the same page as your search box. That way if a search is done it shows the search and if not then it doesn't (example below assumes that the file itself is called welcome.php - so it is 1 file and not 2)


<html>
<body>


<center><form action="welcome.php" method="post" target="_self">
<input type="text" size="40" name="name" /></center>

<center><input type="submit" value="Search" /></center>
</form>

<?php
$search = $_POST["name"];
if (!empty($search)){
echo ("<a href=\"http://www.google.co.uk/search?$search\">http://www.google.co.uk/search?$search</a>");
}
?>
</body>
</html>

jlhaslip
03-04-2008, 08:36 PM
<center>

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" >

<input type="text" size="40" name="name" value = "enter search words here..." /></center>

<center><input type="submit" value="Search" /></center>
</form>

<?php
$search = $_POST["name"];
if (!empty($search)){
echo ("<a href=\"http://www.google.co.uk/search?$search\">http://www.google.co.uk/search?$search</a>");
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum