Answer the question
In order to leave comments, you need to log in
How to submit data only after HTML5 form validation?
There is a form on the site, data is sent via ajax to the server with node js.
<form action="/page-mail" id="email-form" class="form" method="post" onSubmit="return false;">
<input type="text" id="form__fname" name="first_name" placeholder="First Name ">
<input type="text" id="form__lname" name="last_name" placeholder="Last Name ">
<input type="email" class="form__email" name="email" placeholder="Business email *" required>
<input type="phone" class="form__phone" name="phone" placeholder="Phone number *" required>
<p class="error-msg"></p>
<button type="submit" class="form__submit" id='sendButton' >Download now</button>
</form>
$(document).ready(function() {
$("#email-form").submit(function(e) {
var action = $(this).attr("action");
var ser = $(this).serialize();
var that = this;
$.ajax({
type : "POST",
url : action,
data : ser,
complete : function(data) {
if (data.responseText == "true") {
ga('send', 'event', { eventCategory: '', eventAction: ''});
window.location.replace('/page-thank-you');
} else {
$(".error-msg").html('<div class="alert-box alert">' + data.responseText + '</div>');
$("#sendButton").attr('disabled', false);
}
}
});
return false;
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question