Forum Moderators: coopster
After testing this I noticed that it actually checks it as dd/mm/yyyy because I can input 03/13/2008 and it prompts to "Enter a Valid Month"
1. I want to see if anyone has any suggestions on getting it into the mm/dd/yyyy format, as the code seems little like it could possibly be shortened up.
2. This is being used for scheduling, so I only want the user to be able to select dates in the future NOT including the current day. Not sure how to check the inputted date against the current date.
<?php $nextday = mktime(0,0,0,date("m"),date("d")+1,date("Y")); //will create a day after the current one
echo "Next Day: ".date("m/d/Y", $nextday); ?>
====================
//Check the length of the entered Date value
if((strlen($strdate)<10)OR(strlen($strdate)>10)){
echo("Enter the date in 'mm/dd/yyyy' format");
}
else{
//The entered value is checked for proper Date format
if((substr_count($strdate,"/"))<>2){
echo("Enter the date in 'mm/dd/yyyy' format");
}
else{
$pos=strpos($strdate,"/");
$date=substr($strdate,0,($pos));
$result=ereg("^[0-9]+$",$date,$trashed);
if(!($result)){echo "Enter a Valid Date";}
else{
//if(($date<=0)OR($date>31)){echo "Enter a Valid Date";} // original code line
if(($date<=0)OR($date>31)OR($date<$nextday)){echo "Enter a Valid Date or one in the future";}
}
$month=substr($strdate,($pos+1),($pos));
//if(($month<=0)OR($month>12)){echo "Enter a Valid Month";} // original code line
if(($month<=0)OR($month>12)OR($month<$nextday)){echo "Enter a Valid Month or one in the future";}
else{
$result=ereg("^[0-9]+$",$month,$trashed);
if(!($result)){echo "Enter a Valid Month";}
}
$year=substr($strdate,($pos+4),strlen($strdate));
$result=ereg("^[0-9]+$",$year,$trashed);
if(!($result)){echo "Enter a Valid year";}
else{
if(($year<date("Y"))OR($year>2200)){echo "Enter a year between 2008-2200";}
}
}
}
DisplayForm();
}
//User-defined Function to display the form in case of Error
function DisplayForm(){
global $strdate;
===========================
Long story short, I did have a javascript popup calendar in place with an "onKeyDown" event handler that only allowed future dates to be picked...but javascript could be turned off in the users browser, or quirks may prevent it from working in certain browsers correctly. More likely than not javascript will be active in the browser, so another possiblity would be to check the selected date with PHP in case the user finds a workaround and trys to change the selected date to the current day. I appreciate any help...as I have a decent start, but am having problems. Thank you.
Now the first number is in $parts[1], the second in $parts[2], and the third in $parts[3].
You can use checkdate() [php.net] to see if it's a valid date.
To make sure it's greater than today, you can use
$tom = strtotime("tomorrow midnight");
to generate a time stamp for tomorrow, and mktime() with the entered components in the array, then just make sure the entered one is >= $tom.