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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.