Here is my script :
<script>
$('form.subscribe').on('submit', function() {
var that = $(this);
url = that.attr('action');
method = that.attr('method');
data ={};
that.find('[name]').each(function(index, value) {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type:method,
data: data,
success: function(response){
console.log(response);
}
});
return false;
});
</script>
I have an ajax function that gives me either an error message or a success message depending on what your input was on the form.
The messages that I get come from this php script:
<?php
header("Refresh:7; url=contact.php");
$email = $_POST['subscribefield'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Dit emailadres klopt niet";
die();
}
$to = "[email protected]";
$subject = "Abonee voor de nieuwsbrief";
$body = "$email \n Heeft zich aangemeld voor de nieuwsbrief";
mail($to, $subject, $body);
echo "U heeft zich zojuist aangemeld voor de vandenberg nieuwsbrief";
?>
Right now im displaying the outputs with a console.log(). But I would like to display those in a <div> instead.
$('#divid').html(response)in success