I am finishing up a ONE-PAGE responsive website for a client. I am using a Bootstrap contact form at the bottom of the HTML page. There is a second Contact.php file to process the form. The PHP code is showing up in the contact form text fields.
I've read and followed the directions for other folks' similar problems, but my client's URL ends in .HTML so I don't want to make the URL end in .PHP to make the contact form work. Is there a workaround to A) get the code to NOT show up in the text fields, and B) process the form without changing the HTML to PHP. Thanks a bunch - this has been driving me nuts for two days now.
HTML DOC.
<!-- FORM SECTION STARTS HERE---- -->
<section id="contact">
<div class="container">
<div class="row">
<div class="col-md-12">
<h3 class="h3-complete-form">Just complete the form below.</h3>
</div>
</div>
</div>
<form class="form-horizontal" role="form" method="post" action="contact.php">
<div class="row">
<div class="col-sm-3"></div>
<div class="contact-icon">
<i class="fas fa-user"></i>
</div>
<div class="form-inline">
<div class="col-sm-2 form-group">
<label for="name" class="control-label">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name">
<?php
echo $errName;?>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3"></div>
<div class="contact-icon">
<i class="fas fa-envelope"></i>
</div>
<div class="form-inline">
<div class="col-sm-2 form-group">
<label for="email" class="control-label">Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com">
<?php
echo $errEmail;?>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3"></div>
<div class="contact-icon">
<i class="fas fa-pencil-alt"></i>
</div>
<div class="form-inline">
<div class="col-sm-10 form-group">
<label for="message" class="control-label">Message</label>
<textarea class="form-control" rows="4" name="message"
placeholder="How can I help you?">
<?php
echo $errMessage;?>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3"></div>
<div class="contact-icon">
<i class="fas fa-pencil-alt"></i>
</div>
<div class="form-inline">
<div class="col-sm-10 form-group">
<label for="human" class="control-label">2 + 3 = ?</label>
<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer">
<?php echo $errHuman";?>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4"></div>
<div class="form-inline">
<div class="form-group">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
<?php echo $result; ?>
</div>
</div>
</div>
</div>
<!-- Displays an alert to user -->
<div class="row">
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</div>
</form>
</div>
</div>
<!-- --------- SECTION 8: CONTACT ME ENDS HERE------ -->
PHP DOC
<?php include 'validate.php'; ?>
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = "From: ". $name . " <" . $email . ">\r\n";
$to = 'myname@myemailaddress.com';
$subject = 'Message from Contact Form';
$body ="From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your first and last 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 answer is incorrect';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}
}
?>