Forum Moderators: coopster

Message Too Old, No Replies

Passing $string in a form to a URL?

         

kenfused

5:24 am on Apr 29, 2008 (gmt 0)

10+ Year Member



This used to work ok in php4 and now is broken after an upgrade to php5 although I can't figure it out.

I have a form that takes the user to a particular URL depending on the value of the form

<form name="SearchForm" method="POST" action="mysite.com/Search/$SearchKeyword">

<input type="text" size="15" name="SearchKeyword"> <input type=submit value="Search">
</form>

Now the script no longer generates the URL with the user submitted data in the URL

Instead it goes to "mysite.com/search//"

Any ideas?

THANKS

willybfriendly

5:33 am on Apr 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try:

method="GET"

That should append the variable to the URL.

Looks like you are having to clean up a buch of old scripts after upgrading. No fun :(

kenfused

5:45 am on Apr 29, 2008 (gmt 0)

10+ Year Member



THANKS for the quick reply!
yeah my host changed servers with no notice on me! now i'm moving to php 5...

When I change to method "get"

I get the URL www.mysite.com/search/?SearchKeyword=foo

instead of putting the value of "Searchkeyord" into $SearchKeyword it appends this to the end of the action URL
Any ideas?

kenfused

5:46 am on Apr 29, 2008 (gmt 0)

10+ Year Member



I'd prefer the variable in the format

mysite.com/$searchkeyword/

to keep clean URLs that then go thru a mod_rewrite

zolf

2:23 pm on Apr 29, 2008 (gmt 0)

10+ Year Member



try to echo $SearchKeyword to see the variable

kenfused

4:27 pm on Apr 29, 2008 (gmt 0)

10+ Year Member



Where would I do this?
and then if I CAN see the variable, how do I pass it along to the URL?

Is there another way to do this? for example get a script to generate the URL and then Redirect to that generated URL

ag_47

1:05 am on Apr 30, 2008 (gmt 0)

10+ Year Member



<form name="SearchForm" method="GET">

<input type="text" size="15" name="SearchKeyword">
<input type="button" value="Search" onclick="form_sub()">
</form>

Or did I miss something...
I might be mistaken..but you'll probably need javascript.

function form_sub(){

document.SearchForm.action = "mysite.com/Search/?SearchKeyword="+document.SearchForm.SearchKeyword.value;
document.SearchForm.submit();
}