Jump to content

value in value php form


bishop2001

Recommended Posts

greetings,

how do i get the value of a variable from a form. So for example

 

<option value="<? echo $TODAY ?>"><? echo $TODAY ?></option>

 

my drop down menu will show me today's data, but when i select it and click submit

the value in value is not getting interpolated.

Link to comment
Share on other sites

You get the selected value from $_GET or $_POST (depending on your forms submit method), example code

<?php

if(isset($_POST['day']))
{
   echo 'You selected: ' . $_POST['day'];
}

$days = ('Monday', 'Tuesday', 'Wednesday', 'etc...');
?>
<form action="" method="post">
<select name="day">
<?php foreaach($days as $today) {
   <option><?php echo $today ?></option>
<?php } ?>
</select>
<input type="submit" value="Go" />
</form>
Link to comment
Share on other sites

Note that there are a few errors in Ch0cu3r's code. It should look more like the following:

<?php
if(isset($_POST['day']))
{
   echo 'You selected: ' . $_POST['day'];
}
 
$days = array('Monday', 'Tuesday', 'Wednesday', 'etc...');
?>
<form action="" method="post">
<select name="day">
<?php
foreach($days as $today) {
    echo "<option>$today</option>";
}
?>
</select>
<input type="submit" value="Go" />
</form>
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.