I have been turing this php form upside down but I am not finding why the error message is not displaying and the form will always send an email even if all the field are empty. there is my code:
<form name="contactform" method="post" action="">
<input type="text" data-placeholder="<?php echo $name; ?>"name="name">
<input type="text" data-placeholder="<?php echo $email; ?>"name="email">
<textarea data-placeholder="<?php echo $message; ?>" name="message" rows="10"></textarea>
<input type="submit" name="submit" class="btn btn-footer" value="ENVOYER" id="btnContact">
<p class="text desktop"><?php echo $emailErr; ?></p>
</form>
<?php
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$emailErr = "";
if (!isset($name) || $email=="" || $message=="" ) {
$emailErr = "All fields are mendatory";
} else {
$mailTo = "[email protected]";
mail($mailTo);
$emailErr = "Email Send";
}
}
?>
isset()to see if a variable is empty. Use$name == ""like you did with the others.0?