Page 1 of 1

URGENT : How do I auto fill a form field from a URL

Posted: Fri Feb 02, 2007 8:31 pm
by netpants
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Ok when someone goes to my home page index.php and they click on the register link it will bring them to a form. I want to setup 6 images eatch with there own option for example, to register as a human click here, and then it will go to register.php filling in the field they choose from the previous page which was human, and so on for all 6. 

Isnt the url supposed to be somthing like

Code: Select all

http://www.thewebsite.com/register.php?race=Humans
Here is the part in the form I need auto filled. Its pulling the Field names from the database.

Code: Select all

<tr>
		<td class="bodycell4" width="50%" align="right">
			<b>Race:</b>
		</td>
		<td class="bodycell4" width="50%">
			<select name="race">
				<option value="1"><?=$SETTINGS['prace_1']?></option>
				<option value="2"><?=$SETTINGS['prace_2']?></option>
				<option value="3"><?=$SETTINGS['prace_3']?></option>
				<option value="4"><?=$SETTINGS['prace_4']?></option>
				<option value="5"><?=$SETTINGS['prace_5']?></option>
				<option value="6"><?=$SETTINGS['prace_6']?></option>
			</select>
		</td>
	  </tr>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Feb 02, 2007 9:06 pm
by mickd
To retrieve information from the url, use the $_GET variable.

Code: Select all

<?php

// url is http://www.thewebsite.com/register.php?race=Humans

$race = $_GET['race'];

echo $race;

// outputs: Humans

?>
If you want to auto select the race in the url, just use php to check which race is in the url and echo selected="selected" accordingly.

Code: Select all

<option value="2" <?php if(isset($_GET['race']) && $_GET['race'] == 'NameOfRace2') echo 'selected="selected"'; ?>><?=$SETTINGS['prace_2']?></option>