I'm working on an ExpressionEngine 3.5.10 website which uses the native Email module and contact form.
I'm also using the jQuery validate.js plugin, version 1.15.0.
The form is submitted with ajax and validated by the validate.js plugin:
$("#contactUsForm").validate({
rules: {
"firstName": "required",
"lastName": "required",
"email": {
required: true,
email: true
},
"comments": "required"
},
messages: {
"firstName": "Please enter your first name",
"lastName": "Please enter your last name",
"email": {
required: "Please enter your email address",
email: "Your email address must be in the format of [email protected]"
},
"comments": "Please enter a message"
},
submitHandler: function(form) {
var dataString = $( "form" ).serialize();
$.ajax({
type: 'POST',
url: $("#contactUsForm").attr('action'),
data: dataString,
success: function(msg){
$('#contactFormContainer').html('');
$('#contactFormContainer').append('<h3>Thanks, we\'ve received your message and will be in touch shortly!</h3>');
},
error: function(xhr, status, error) {
$('#contactFormContainer').html('');
$('#contactFormContainer').append('<h3>Sorry, an error has occured. Please contact us using the details given below.</h3>');
}
});
return false;
}
});
This all works and the form is posted to the correct URL - defined in $("#contactUsForm").attr('action')
However, after this post is made, I need to make a second post, to a different URL.
So I added the following code in my submitHandler
:
$.ajax({
type: "POST",
url: "/site/test",
data: dataString,
dataType: "json",
success: function(data) {
console.log('success');
console.log(data);
},
error: function() {
console.log('error!');
}
});
When I do this, the post request is made to /site/test
but ExpressionEngine returns the following error message:
You are only allowed to submit email forms every 20 seconds
I understand this is an ExpressionEngine specific error. But, is there any way around this, or a different way to get it to do the post request to the separate URL?