Mko Posted April 5, 2012 Share Posted April 5, 2012 So I have the following code, which is supposed to get the value selected by the user, then on submitting, will use that value in the URL. $durations = array("1", "2", "3", "4", "5", "7", "10", "10000000"); echo "Choose Duration: ";?><form method="post" action=""><select name="duration_chosen"> <? foreach($durations as $duration){ ?><option name="duration_len" value="<?php echo $duration;?>"> <? if ($duration == "10000000") { echo "Forever"; } else { echo "$duration day(s)"; } ?></option><? } ?> </select></form><? $hrs = $_GET['duration_len'] * 24; $duration_chosen = $_POST['duration_chosen']; ?> <form method="get" action="index.php"> <input type="hidden" name="duration" value="<? echo $duration_chosen; ?>"> <input type="submit" value="Accept"></form> For some reason, though, it doesn't work. Can anyone help me? Thanks, Mark Link to comment https://forums.phpfreaks.com/topic/260392-select-menus/ Share on other sites More sharing options...
smerny Posted April 5, 2012 Share Posted April 5, 2012 your form method is POST, if you want to get form input with GET (and have them show up in the URL), you must use form method="get" actually looked at your code again and i'm not sure what you are doing... there are two forms and there is no submit for the first form? Link to comment https://forums.phpfreaks.com/topic/260392-select-menus/#findComment-1334602 Share on other sites More sharing options...
smerny Posted April 5, 2012 Share Posted April 5, 2012 also you should use the full php tag rather than the short tag... from what i can see... you are trying to do something like this: $durations = array("1", "2", "3", "4", "5", "7", "10", "10000000"); echo "Choose Duration: ";?><form method="get" action="index.php"><select name="duration_chosen"> <?php foreach($durations as $duration){ ?><option name="duration" value="<?php echo $duration;?>"> <?php if ($duration == "10000000") { echo "Forever"; } else { echo "$duration day(s)"; } ?></option><?php } ?> </select> <input type="submit" value="Accept"> </form> and then you can process $_GET['duration'] on the page this form is getting sent to Link to comment https://forums.phpfreaks.com/topic/260392-select-menus/#findComment-1334604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.