Another question about the contact form. I tried getting the bootstrap modal on the same page after it's send through the php script. Sadly enough I failed everytime, and now I'm a bit stuck.
What I want it do to... After clicking on the submit button, the contact form must be send by the php script, and after that the "ThankyouModal" should pop-up on the page where the contact form is.
Here's the HTML :
<div class="container main-container">
<div class="col-md-6">
<form action="contact-page.php" method="post">
<div class="row">
<div class="col-md-12">
<div class="input-contact">
<input type="text" name="name">
<span>Naam</span>
</div>
</div>
<div class="col-md-12">
<div class="input-contact">
<input type="text" name="email">
<span>E-mailadres</span>
</div>
</div>
<div class="col-md-12">
<div class="textarea-contact">
<textarea name="message"></textarea>
<span>Bericht</span>
</div>
</div>
<div class="col-md-12">
<!-- <a class="btn btn-box" input type="submit" name="submit" value="Send">Verzenden</a> -->
<button type="submit" name="submit" class="btn btn-box">Verzenden</button>
</div>
</div>
</form>
</div>
Here's the PHP script :
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<!-- Main CSS -->
<link rel="stylesheet" href="css/style.css">
<!-- Js -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<?php
if(isset($_POST['submit'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "test@test.com";
// EDIT THE 2 LINES BELOW AS REQUIRED
$sender = $_POST['email'];
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$message = $_POST['message']; //required
$email_message = "Hieronder staan alle gegevens.\n\n";
$email_subject = "Contact details - $name";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Naam: ".clean_string($name)."\n";
$email_message .= "E-mailadres: ".clean_string($email)."\n";
$email_message .= "Bericht: ".clean_string($message)."\n";
// create email headers
$headers = 'From:'.$sender."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
$sent= @mail($email_to, $email_subject, $email_message, $headers);
if($sent){
echo "<script>
$(document).ready(function(){
$('#thankyouModal').modal('show');
});
</script>";
}
else {
echo "<script>
alert('Sorry! Er is iets mis gegaan, probeer het opnieuw.')
location.replace('contact.html')
</script>";
}
}
?>
</head>
<body>
<div class="modal fade" id="thankyouModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h2 class="modal-title text-center" style="font-weight: 600; color: #393939;">BEDANKT</h2>
</div>
<div class="modal-body text-center" style="background-color: #fff;">
<p style="font-weight: 600; color: #393939; font-size: 18px;">Ik neem zo spoedig mogelijk contact op!</p>
</div>
<div class="modal-footer" style="background-color: #fff; border-top: 0px solid #fff;">
<button type="button" class="btn btn-box" aria-label="Close"><a href="contact.html" style="color:fff;" data-dismiss="modal" onclick="javascript:window.location='contact.html'">Sluiten</a></button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>
I realize that it's all the fields are in Dutch language, but the code must be universal. Maybe if there's a solution for the pop-up thing I would also like to know how to implement the same pop-up for the "failed" message.
Thanks in advance guys! Kevin