-
-
Save askkaz/44ba29cf1898c60e3eb03903e63e2cc4 to your computer and use it in GitHub Desktop.
Webflow Form Submission for Loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
/* apply only to forms with the action pointing to Loops */ | |
$('form[action^="https://app.loops.so"]').each(function (i, el) { | |
form = $(el); | |
form.submit(function (e) { | |
/* stop the form from submitting */ | |
e.preventDefault(); | |
form = $(e.target); | |
action = form.attr('action'); | |
/* submit the form via ajax */ | |
$.ajax({ | |
url: action, | |
method: "POST", | |
data: form.serialize(), | |
dataType: "json", | |
success: function (data) { | |
if (data.success) { | |
/* successful submission - hide the form and show the success message */ | |
parent = $(form.parent()); | |
parent.children('form').css('display', 'none'); | |
parent.children('.w-form-done').css('display', 'block'); | |
} else { | |
parent = $(form.parent()); | |
parent.find('.w-form-fail').css('display', 'block'); | |
} | |
}, | |
error: function () { | |
/* failed submission - show the failure message */ | |
parent = $(form.parent()); | |
parent.find('.w-form-fail').css('display', 'block'); | |
} | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment