mdisch Posted February 26, 2009 Share Posted February 26, 2009 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 More sharing options...
micah1701 Posted February 26, 2009 Share Posted February 26, 2009 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> Link to comment https://forums.phpfreaks.com/topic/147046-automatically-set-field-from-url/#findComment-771977 Share on other sites More sharing options...
napurist Posted February 26, 2009 Share Posted February 26, 2009 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. Link to comment https://forums.phpfreaks.com/topic/147046-automatically-set-field-from-url/#findComment-771979 Share on other sites More sharing options...
mdisch Posted February 26, 2009 Author Share Posted February 26, 2009 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. Link to comment https://forums.phpfreaks.com/topic/147046-automatically-set-field-from-url/#findComment-771992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.