I made a contact form following this tutorial : http://tinyurl.com/nyxv8ub
Everything is working but some parameters are not adressed.
As a matter of fact, on submit, if the user hasn't filled the form properly he is notified and all fields clear themselves.
It is a pain for the user to re-type his message, so I'd like him to be notified of his mistakes without clearing any field.
Currently, there are 2 ways to get the form wrong. Whether you don't fill the Email or Name fields, or when the answer to the spam question is wrong.
Is it possible to prevent this from happening?
You can find the form here : http://bettercheckthekids.com/Form/index.php
And here is the php :
<?php
$name = $_POST['name'];
$firm = $_POST['firm'];
$email = $_POST['email'];
$list = $_POST['list'];
$message = $_POST['message'];
$spam = $_POST['spam'];
$from = 'From: Adiwatt Online';
$to = 'clement.fauquet@gmail.com';
$subject = 'Hello';
$body = "From: $name\n Firm: $firm\n E-Mail: $email\n Objet: $list\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($spam == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $spam != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
}
?>