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

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.