This question already has an answer here:
- How to validate an email address in PHP 10 answers
I have a form where I ask for information, but some (such as email) is not required. When the form for email is not empty, I'd like the email to be validated and sanitized. My current method only submits the data that is not empty. What's the most effective way to do the validation and sanitization?
Current method
if (empty($_POST["S_Email"])) {
$S_Email = "";
} else {
$S_Email = $_POST["S_Email"];
}
</div>