Jump to content

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
https://forums.phpfreaks.com/topic/260392-select-menus/
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
https://forums.phpfreaks.com/topic/260392-select-menus/#findComment-1334604
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.