Forum Moderators: coopster

Message Too Old, No Replies

From html form to a sitengine link

         

FnTm

5:18 pm on Jul 20, 2007 (gmt 0)

10+ Year Member



Hi all of you pro coders here. Been at this for about 3 weeks or so, and now I would need your help...

My problem is this. I want a code, that would allow the phrase that i type in my html/php form, to be automatically put into a link in a search engine. I know how to do this with frames using variables, but how could i do that with opening new pages?
How I would like it to go:

www.mypage.com/search contains a webform. I input a phrase like BOB in the webform, and it transfers me to a link like [google.com ]

All i need is the corect syntax how to input that there...

jatar_k

5:29 pm on Jul 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld FnTm,

all you owuld need to do is grab the value from your $_POST array, concatenate it into your string (url) and then feed that string to the header function.

if your textbox was call 'searchterm' then it might look something like

$st = $_POST['searchterm'];
$url = 'http://www.google.com/search?hl=en&q=' . $st . '&btnG=Google+Search';
header("Location: $url");

this would send them off to google with the required url. I did not add any data verification to the first line which you should add but you can test this to see if it does what you want.

FnTm

6:15 pm on Jul 20, 2007 (gmt 0)

10+ Year Member



Thanks for the reply, but i was just wondering... Could you please write the whole script that i need to put in my site? Because I am not quite familiar with the input types too...

Thanks allready!

Gian04

11:19 am on Jul 21, 2007 (gmt 0)

10+ Year Member



From the WW Charter - PHP Server Side Scripting

Fix my code/Do My Homework posts are not all that welcome. This is a discussion board, if you have a problem, try to phrase your post in a manner condusive to discussion of the issue. We want to teach people to help themselves. (Give a man a fish, and you feed him for a day. Teach a man to fish, you feed him for a life time.

jatar_k

2:04 pm on Jul 21, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



since it is simple I will give you the whole code, honestly most of it is listed above

save the above code to a file with whatever name you like, let's call it redir.php

then you make a form and add that script name to the form action. For this example the files need to be in the same directory. Something like this would be fine

<form name="getsearchterm" method="post" action="redir.php">
<br>enter your search term: <input type="text" name="searchterm">
<br><input type="submit" value="Search for it">
</form>

give that a shot

FnTm

5:52 am on Jul 23, 2007 (gmt 0)

10+ Year Member



Thanks man! It works great, and my boss is happy, so I'm very happy too :D Thanks!

eelixduppy

7:39 am on Jul 23, 2007 (gmt 0)



Glad everyone is happy, FnTm :)

And welcome to WebmasterWorld!