Hello everyone! I just created a form with Bootstrap framework via a tutorial that used PHP so send the form. I placate PHP in the html file and then saved as PHP and uploaded to my site. All is looking good and the modal is working properly however, the validation and mail submission isn’t. Any suggestions?
[php]<?php
if ($_POST[“submit”]) {
$name = $_POST[‘name’];
$email = $_POST[‘email’];
$message = $_POST[‘message’];
$human = intval($_POST[‘human’]);
$from = ‘Contact Form’;
$to = ‘REMOVED’;
$subject = ‘Message from Contact’;
$body ="From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
$result=‘
} else {
$result=‘
}
}
}
?>
[/php]
And the HTML
[code]
<div class="form-group">
<label class="col-sm-2 control-label" for="inputName">Name</label>
<div class="col-sm-10">
<input class="form-control" id="inputName" name="name" placeholder="Name" type="text" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div><!-- end col-sm-10 -->
</div><!-- end form-group -->
<div class="form-group">
<label class="col-sm-2 control-label" for="inputEmail">Email</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail" name="email" placeholder="[email protected]" type="email" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div><!-- end col-sm-10 -->
</div><!-- end form-group -->
<div class="form-group">
<label class="col-sm-2 control-label" for="inputMessage">Message</label>
<div class="col-sm-10">
<textarea class="form-control" id="inputMessage" name="message" placeholder="What's On Your Mind?" rows="4"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div><!-- end col-sm-2 -->
</div><!-- end form-group -->
<div class="form-group">
<label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
<?php echo "<p class='text-danger'>$errHuman</p>";?>
</div><!-- end col-sm-10 -->
</div><!-- end form-group -->
<div class="form-group">
<div class="col-sm-12">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-contact pull-right">
</div><!-- end col-sm-12 -->
</div><!-- end form-group -->
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div><!-- end col-sm offset-2 -->
</div><!-- end form-group -->
</form><!-- end form -->
[/code]