There's an html form for email subscribing which is connected to mailerlite,
<form class="ml-block-form" action="" data-code="ID" method="POST">
<div class="form-group ml-field-email ml-validate-required ml-validate-email">
<input id="mainval" class="newsletter-email" type="email" name="fields[email]" placeholder="Enter email address" />
</div>
<input type="hidden" name="ml-submit" value="1" />
<p>
<input id="formsubmit" class="newsletter-submit" type="submit" value="Submit" />
</p>
</form>
and this is the ajax part:
$(".ml-block-form").submit(function() {
var vals = $(this).serialize();
$.ajax({
url: "//app.mailerlite.com/webforms/submit/ID",
method: "POST",
data: vals,
success: function(data) {
$("#formsubmit").val("Thanks");
$('#formsubmit').css('background-color', '#6cd270');
}
});
return false; // prevent from submit
});
Now the problem is that even if someone enters an invalid email address, or just hitting the submit button without entering any email address, It will work.
How can I verify the email address to find out if it's correct, using ajax before sending it to mailerlite via POST method?