Hello friends,
in my form i am having 3 date fields......i got this date function
<?php
//This function makes 3 pulldown menus for the months, days, and years.
function make_calendar_pulldowns2($m2 = NULL, $d2 = NULL, $y2 = NULL)
{
//Make the months array.
$months2 = array (1 => 'January','February','March','April','May','June','July','August','September','October','November','December');
//Make the months into a pulldowm.
echo '<select name="month2">';
foreach ($months2 as $key => $value)
{
echo "<option value=\"$key\"";
if ($key == $m2);
{
//Preselect.
echo ' selected="selected"';
}
echo ">$value</option>\n";
}
echo '</select>';
//Make the days pull-down menu.
echo '<select name="day2">';
for ($day2 = 1; $day2 <= 31; $day2++)
{
echo "<option value=\"$day2\"";
if ($day2 == $d2)
{
//Preselect.
echo ' selected="selected"';
}
echo ">$day2</option>\n";
}
echo '</select>';
//Make the years pull-down menu.
echo '<select name="year2">';
for ($year2 = 1950; $year2 <= 2022;
$year2++)
{
echo "<option value=\"$year2\"";
if ($year2 == $y2)
{
//Preselect.
echo ' selected="selected"';
}
echo ">$year2</option>\n";
}
echo '</select>';
}//End of Function Definition
//Get today's date and call the function.
$dates2 = getdate();
$date_birth= make_calendar_pulldowns2($dates2['mon'],$dates2['mday'],$dates2['year']);
$date2= make_calendar_pulldowns2($dates2['mon'],$dates2['mday'],$dates2['year']);
?>
can any body tell me how to validate (leap year and all)...........
please tell me how can i use it....thanks
how to validate drop dowan calendar in php
Moderator: General Moderators
Re: how to validate drop dowan calendar in php
Please use the code tags when you're posting code!!
As far as leap years go:
1. Every year that is evenly divisible by four is a leap year;
2. of those years, if it can be evenly divided by 100, it is NOT a leap year, unless
3. the year is evenly divisible by 400. Then it is a leap year.
Otherwise setup an array called endmonth. For each month enter the last day in that month. For February you can use a function that calculates if it's a leap year or not.
As far as leap years go:
1. Every year that is evenly divisible by four is a leap year;
2. of those years, if it can be evenly divided by 100, it is NOT a leap year, unless
3. the year is evenly divisible by 400. Then it is a leap year.
Otherwise setup an array called endmonth. For each month enter the last day in that month. For February you can use a function that calculates if it's a leap year or not.
Code: Select all
$leapyear = isLeapYear($year);
$endmonth = array(1=>31, 2=>$leapyear, 3=31, 4=30...);
//now you can use something like a function called validate
if ($_POST['day'] > $endmonth[$_POST['month']])
; //error
else
; //this is a valid date