Welcome to WebmasterWorld Guest from 54.147.10.72

Forum Moderators: phranque

Message Too Old, No Replies

How to make URL reflect form input

     

kodaks

11:43 pm on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello everyone!

I would like to know if there is a way to make whatever the URL used to get to a page is, reflect on the input of a form on that page. I know most of you are going "huh?" right now, so allow me to explain.

A user goes to a URL like:
http://www.example.com/member.php?name=John

On the member.php page, there is a form and one of the inputs is "name".

So when the page loads, "John" will already be in one of the form's fields.

I hope this is not too confusing, and thanks in advance for any assistance.

rocknbil

11:54 pm on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You output the form dynamically, with appropriate variables in the value fields. If the form is called without a query string, they will be blank (as the values are null.)

A perl-ey example:

http://www.example.com/member.cgi?name=John

%qs = &query; ## Read/parse, associates $qs{'name'} = 'John';

print "content-type: text/html\n\n";

print <<"EOFORM";
<html><head><title>Hello $qs{'name'}</title></head></html>

<body>
<h3>Hello $qs{'name'}</h3>

<form>
<input type="text" name="name" value="$qs{'name'}">
</form>
</body>
</html>

EOFORM

You can do this using the language of your choice, or if on a static page, with Javascript or VBScript. The methods will differ, but the concept is the same, parse a query string/form post and use the variables to populate the form.

kodaks

11:57 pm on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you very much for your reply!

Is there any way I can do this with php or html?

kodaks

1:13 am on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Added:
It seems that Vbulletin uses this kind of script to when you try to register. It asks you what your birthday is and then the next page displays as:
[forumname.com...] month=6&year=1984&day=2

Anybody know how else to do this? Thanks!

Dijkgraaf

1:22 am on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes you can do it with PHP, no for just HTML as that is just a markup language, you need to use something in addition to HTML such as JavaScript, PHP, Perl, ASP etc. to fill in the field.
With your example of
?month=6&year=1984&day=2
then with PHP you would have
<input name="month" value="<? echo $month?>">

kodaks

1:31 am on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, will try!

rocknbil

5:44 pm on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



as I mentioned, you can do it in a static HTML page BUT you must use Javascript, VBscript, or some other client-side language.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month