What are some common pitfalls when using filter_var in PHP for form validation?

One common pitfall when using filter_var in PHP for form validation is not specifying the correct filter type, leading to unexpected validation results. To avoid this issue, always specify the appropriate filter type according to the input data you are validating. Additionally, make sure to handle the return value of filter_var properly to account for false positives or negatives.

// Example of using filter_var with correct filter type and handling return value
$email = $_POST['email'];

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // Email is valid
    echo "Email is valid";
} else {
    // Email is invalid
    echo "Email is invalid";
}