Jump to content

form validation


sofia403

Recommended Posts

Something like this as an example:

 

if(empty($_POST['year']) || empty($_POST['month']) || empty($_POST['day'])) {
// one or all is empty do something here like redirect back so user can insert values
$date_ok = false;
} else {
// all have values continue with code
$date_ok = true;
}

 

or can even do more checks on it and the other way, must be set and not empty for each

if(isset($_POST['year']) && !empty($_POST['year']) && isset($_POST['month']) && !empty($_POST['month']) && isset($_POST['day']) && !empty($_POST['day'])) {
//continue with code only if all above conditions are met
}

 

whichever way you do it you must check all 3 values separate, not as one empty plus other code just used for displaying purposes. Or in this case you manually assembling your date.

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.