bishop2001 Posted June 12, 2014 Share Posted June 12, 2014 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 https://forums.phpfreaks.com/topic/289126-value-in-value-php-form/ Share on other sites More sharing options...
Ch0cu3r Posted June 12, 2014 Share Posted June 12, 2014 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 https://forums.phpfreaks.com/topic/289126-value-in-value-php-form/#findComment-1482539 Share on other sites More sharing options...
cyberRobot Posted June 12, 2014 Share Posted June 12, 2014 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 https://forums.phpfreaks.com/topic/289126-value-in-value-php-form/#findComment-1482561 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.