Hi,
I have a function which creates month, year and day dropdown menus. I want to be able to use this function a number of times (i.e. a number of different dates will be set at different places on the page which calls it) so I have set the value of <select name=""> to be set dynamically when the function is called.
The function looks like this:
function date_form($month, $day, $year, $m=NULL, $d=NULL, $y=NULL) {
//create months dropdown
//create months array
$months=array(1=>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
echo '<select name="' . $month . '">\n';
//being loop through array to create items for dropdown
foreach ($months as $key=>$value){
echo "<option value=\"$key\"";
if($key==$m){
echo ' selected="selected"';
}
echo ">$value</option>\n";
}
echo '</select>';
//begin day dropdown
echo '<select name="' . $day . '">\n';
for($day=1; $day<=31; $day++){
echo "<option value=\"$day\"";
if($day==$d){
echo ' selected="selected"';
}
echo ">$day</option>\n";
};
//begin year dropdown
echo '<select name="' . $year . '">\n';
for($year=2009; $year<=2020; $year++){
echo"<option value=\"$year\">$year</option>\n";
if($year==$y){
echo ' selected="selected"';
}
echo ">$year</option>\n";
}
echo '</select>
<input type="submit" name="submit" value="Enter date" />
<input type="hidden" name="submitted" value="TRUE" />';
if(isset($_POST['submitted'])){
echo "{$_POST['" . $month . "']}";
}
}
and the code on the page that calls it looks like this:
$dates=getdate();
$sowmonth='sowmonth';
$sowday='sowday';
$sowyear='sowyear';
date_form($sowmonth, $sowday, $sowyear, $dates['mon'], $dates['mday'], $dates['year']);
This works fine in setting the values of <select name=""> but it causes me problems when I want to do something with the values that are submitted. Basically I never know what the $POST[''] value is going to be. You can see at the bottom of the function I have tried
if(isset($_POST['submitted'])){
echo "{$_POST['" . $month . "']}";
but it doesn't work.
Can anyone help? 😕 Thanks!