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. Quote Link to comment 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> Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.