mysql php check form for empty input fields
243
if(empty($_POST['inputEmail'])) {
function valid_mail($str) {
return filter_var($str, FILTER_VALIDATE_EMAIL) ? $str : false;
}
echo 'Please enter a valid email address' . "<br />";
}
Answer
Solution:
You may also use the
required
-attribute on required form-fields. You can also use HTML5-input-types, like<input type="mail" />
for client-side checks. Both methods which can be "hacked", but prevents "normal" user to send a not-correctly-filled form. Use PHP's filter_var-function, to validate the mail-address on the server.Answer
Solution:
use a temporary variable:
$validation_error = false;
Answer
Solution:
A better mail validation function could be:
or using PHP filter_var (thanks @feela)