stuart7398 Posted March 29, 2008 Share Posted March 29, 2008 Hi. How would I do the following? On my website will be a contact us page with a drop down menu with 'subjects' For example Request a brochure Make a complaint Make a suggestion When the user lands on the 'contact us' page how can I get the subject box to automatically show the option from the page they have come from? So coming from request a brochure page the subject area will show 'Request a brochure' and so on. Any help is appreciated. Thanks Stu. Quote Link to comment https://forums.phpfreaks.com/topic/98477-how-can-i-achieve-this/ Share on other sites More sharing options...
ucffool Posted March 29, 2008 Share Posted March 29, 2008 You want to place the SELECTED statement within the option. The quick and dirty way would be: <!-- $_SERVER['HTTP_REFERER'] will show the page they came from --> <select name='subjects' id='subjects'> <option <?php if ($_SERVER['HTTP_REFERER'] == 'urlofapage') { echo 'SELECTED'; } ?> value='brochure'>Request a brochure</option> <option <?php if ($_SERVER['HTTP_REFERER'] == 'urlofadifferentpage') { echo 'SELECTED'; } ?> value='complaint'>Make a complaint</option> <option <?php if ($_SERVER['HTTP_REFERER'] == 'urlofanotherpage') { echo 'SELECTED'; } ?> value='suggestion'>Make a suggestion</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/98477-how-can-i-achieve-this/#findComment-503959 Share on other sites More sharing options...
monkeytooth Posted March 29, 2008 Share Posted March 29, 2008 Assuming that your coding your page and have an understanding of the coding being used.. I am going to say. Just use some simple variables. You will need to change your links up a bit that link to the form to include said variables. so if your links are something to the effect of www.yourdomain.com/form.php you could change it to www.yourdomain.com/form.php?subj=reqst Where reqst would be your variable. Then in the form.php add a couple simple if-else-then style statements (pending how your server is set up and what PHP version you have this may vary). But just set them up to find the variable. Example: <?php if ($_Get['subj'] == "") { //leave field blank.. for user input } elseif ($_Get['subj'] == "reqst") { $subj = "1"; } else { //leave field blank.. for user input } ?> It gets complicated with the essence of a drop down box, but.. <select size="1" name="D1"> <option value="none" <?php if (!isset($subj)) { echo "selected"; ?>>--select--</option> <option value="1" <?php if ($subj == "reqst") { echo "selected"; ?>>Request Brocher</option> <option value="2" <?php if ($subj == "var2") { echo "selected"; ?>>blah</option> <option value="3" <?php if ($subj == "var3") { echo "selected"; ?>>something</option> </select> I might be making things more complicated then need be.. but that usually works for me.. when I'm working on forms.. If anyones got a better idea, by all means let it be known, I could use something better if it exists when im workin on forms.. :-) Quote Link to comment https://forums.phpfreaks.com/topic/98477-how-can-i-achieve-this/#findComment-503972 Share on other sites More sharing options...
soycharliente Posted March 29, 2008 Share Posted March 29, 2008 selected="selected" Not just selected Quote Link to comment https://forums.phpfreaks.com/topic/98477-how-can-i-achieve-this/#findComment-503974 Share on other sites More sharing options...
monkeytooth Posted March 29, 2008 Share Posted March 29, 2008 Actually viewing my own post.. the first if statement really isn't necessary, well not per say.. at least.. I would use it along with for other means, but not for the form element.. Was kinda typing without thinking, sorry for any confusion.. Quote Link to comment https://forums.phpfreaks.com/topic/98477-how-can-i-achieve-this/#findComment-503977 Share on other sites More sharing options...
ucffool Posted March 29, 2008 Share Posted March 29, 2008 selected="selected" Not just selected Um, not, you are wrong. just SELECTED is necessary. http://htmlhelp.com/reference/html40/forms/option.html Quote Link to comment https://forums.phpfreaks.com/topic/98477-how-can-i-achieve-this/#findComment-503998 Share on other sites More sharing options...
wildteen88 Posted March 29, 2008 Share Posted March 29, 2008 selected="selected" Not just selected Um, not, you are wrong. just SELECTED is necessary. http://htmlhelp.com/reference/html40/forms/option.html That is fine if you're using plain HTML4. However if you're using XHTML then you'll have to use select="select" Quote Link to comment https://forums.phpfreaks.com/topic/98477-how-can-i-achieve-this/#findComment-504121 Share on other sites More sharing options...
soycharliente Posted March 30, 2008 Share Posted March 30, 2008 Um, not, you are wrong. just SELECTED is necessary. http://htmlhelp.com/reference/html40/forms/option.html Page using selected and it's validation Page using selected="selected" and it's validation Quote Link to comment https://forums.phpfreaks.com/topic/98477-how-can-i-achieve-this/#findComment-504738 Share on other sites More sharing options...
ucffool Posted March 30, 2008 Share Posted March 30, 2008 no, I won't disagree that under XHTML selected="selected" is correct. It's just a simple matter of assumptions. You assumed they were using XHTML, I assumed HTML. It's just that simple. It's the OP's fault. ;-) We are both right... maybe. Quote Link to comment https://forums.phpfreaks.com/topic/98477-how-can-i-achieve-this/#findComment-504743 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.