Since you call the validate(form) function on the submit and add the submit handler to the button after it, but do not call it.
Decision. The handler for sending a call after joining, click the send button on the button.
$('#submitbtn').click();
Like this
if (fail == "") { $(function () { $('#submitbtn').click(function (event) { event.preventDefault(); var form = $(this).closest('form'), action = form.attr('action'); $.post(action, form.serialize(), function (data) { $('#errors').html("You have been successfully subscribed to our newsletter."); }) }).click(); }); }
or
Itβs better not to attach a submit handler, just run the AJAX request directly if the condition is true.
like this
if (fail == "") { action = $(form).attr('action'); $.post(action, $(form).serialize(), function (data) { $('#errors').html("You have been successfully subscribed to our newsletter."); }) }
source share