Jump to content

help with date validation


sofia403

Recommended Posts

Im curently using below code to check so that the date is entered (DATE1 required field) I also have another date form (DATE2) but its not required, however i want the user IF he starts entering DATE2 - fill out the whole date and not just partial (month or day or year) can someone sugest how i can do that?

 

thank you.

 

if( empty($_POST['year'])){
header("Location:Messages.php?msg=18"); 
exit();
}
if( empty($_POST['day'])){
header("Location:Messages.php?msg=18"); 
exit();
}
if( empty($_POST['month'])){
header("Location:Messages.php?msg=18"); 
exit();
}

Link to comment
Share on other sites

Just need a complex if statement.

 

Here's what you want

 

if( empty($_POST['year']) || empty($_POST['month']) || empty($_POST['day']) ){
echo 'First date not entered';
exit();
} elseif( (!empty($_POST['year2']) || !empty($_POST['month2']) || !empty($_POST['day2'])) &&
(empty($_POST['year2']) || empty($_POST['month2']) || empty($_POST['day2'])) ) {
echo 'Partial second date entered';
exit();
}

echo 'Everything works out fine';

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.