Hi all,
Im learning PHP recently so a bit of a noob here...
I'm making a purely php form(without using JS for the moment) which has 2 date selection SELECT boxes displaying month/day
Pls note that I need to be able to return the previously selected Value of these Select Boxes after POST(if the validation Fails)
I'm making all three of these dynamically but I'm facing a confusing problem to which I seek help..All of these Dynamically created drop boxes take the highest value selected on any of the one after post...
somekind of mixing of variable or POST vars is going on
<?php
echo '
<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
$months = range (1,12);
$days = range (1, 31);
$years = range (2010, 2015);
//******* Display the Drop Down Boxes ***************************************
echo "Month: <select name='month' id='month'>";
foreach ($months as $value) {
echo (in_array($value,$_POST)) ? '<option value="'.$value.'" selected>'.$value.'</option>\n' : '<option value="'.$value.'">'.$value.'</option>\n';
} echo '</select><br />';
echo "Day: <select name='day' id='day'>";
foreach ($days as $value) {
echo (in_array($value,$_POST)) ? '<option value="'.$value.'" selected>'.$value.'</option>\n' : '<option value="'.$value.'">'.$value.'</option>\n';
} echo '</select><br />';
echo "Year: <select name='year' id='year'>";
foreach ($years as $value) {
echo (in_array($value,$_POST)) ? '<option value="'.$value.'" selected>'.$value.'</option>\n' : '<option value="'.$value.'">'.$value.'</option>\n';
}
echo '</select><input type="submit" /></form>';
?>
can u pls Advice