Since I didn't like how empty() considers 0 and "0" to be empty (which can easily lead to bugs in your code), and since it doesn't deal with whitespace, i created the following function:
<?php
function check_not_empty($s, $include_whitespace = false)
{
if ($include_whitespace) {
$s = trim($s);
}
return (isset($s) && strlen($s)); }
?>
Instead of saying if (!empty($var)) { // it's not empty } you can just say if (check_not_empty($var)) { // it's not empty }.
If you want strings that only contain whitespace (such as tabs or spaces) to be treated as empty then do: check_not_empty($var, 1)
If you want to check if a string IS empty then do: !check_not_empty($var).
So, whenever you want to check if a form field both exists and contains a value just do: if (check_not_empty($_POST['foo'], 1))
no need to do if (isset() && !empty()) anymore =]