Jump to content

Automatically Set Field from URL


mdisch

Recommended Posts

I have a contact form working perfectly fine with POST method in PHP after clicking submit button (http://www.gvrrid.org/contact).  Now my question is how do I set the selected field box To: with value of President automatically reading from the URL (http://www.gvrrid.org/contact/?to=President)?  I have tried changing to GET method and it still doesn't work.

 

Link to comment
https://forums.phpfreaks.com/topic/147046-automatically-set-field-from-url/
Share on other sites

I'm not sure I understand the problem...

 

is the HTML field a simple text field?  If so this should work:

<input type="text" value="<?php echo $_GET['to'] ?>">

 

if the HTML field is something like a <select> drop down box, then you would need to change it up a bit; like:

 

<select name="to">
<option value="President" <?php if($_GET['to'] == "President"){ echo "selected"; } ?> >President</option>

</select>

Your contact form would need to be accessed via a link like this.

 

http://www.gvrrid.org/contact/index.php?to=president

 

Then your contact page "index.php" would need a statement such as

 $to = $_GET['to']; 

 

You can then run an if statement, as you would like, to set the SELECTED option for the drop down.

Here is what I had

 

<select name="to" size="1" value="<?php if(isset($_GET['to'])) echo $_GET['to']; ?>"/>
		<option selected value=" ">select one</option>
		<option value="President">President - Kimberly Kelstone</option>
		<option value="Vice President">Vice President - Aaron J. Gorelick</option>
        <option value="Secretary">Secretary - Elisa Mlynar</option>
        <option value="Treasurer">Treasurer - Don Heinz</option>
        <option value="Director">Director - Kathryn Petersen, Carmen Sciandra, Brent Bocian</option>
        <option value="SIAR">Student Interpreting Association Representative - Courtney Williams</option>
		<option value="GVRBoard">GVR Board - all of the above</option>
	</select>

 

Thanks, that helps what I didn't have is echo selected with if.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.