Jump to content

Select Menus


Mko

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.