complex if statement for field validation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
I've got a form with three fields that are not required for proper
completion of it, ending month, day, year fields. If a user enters
nothing no problem, but if those form fields are entered I need them
validated. They have to be in the correct format YYYY-MM-DD date
format and that value also has to be greater than the starting date
validated previously. I've got some not working code.
Thanks.
Dave.

// if an ending date field was entered validate that
// also must be greater than the starting date values
if(!empty($_POST['month1']) && !empty($_POST['day1']) &&
!empty($_POST['year1']) {
$month1=$_POST['month1'];
$day1=$_POST['day1'];
$year1=$_POST['year1'];
$date_value1="$year1-$month1-$day1";
}
if(!checkdate($month1,$day1,$year1)) {
echo "Invalid Date.\n";
} else {
echo "Entered Date is correct.\n";
}
}
if(!checkdate($month1,$day1,$year1)) > $date_value {
echo "Invalid Date.\n";
} else {
echo "Entered Date is correct.\n";
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux