Skip to content

Instantly share code, notes, and snippets.

@askkaz

askkaz/before.js Secret

Created April 29, 2022 15:00
Show Gist options
  • Save askkaz/44ba29cf1898c60e3eb03903e63e2cc4 to your computer and use it in GitHub Desktop.
Save askkaz/44ba29cf1898c60e3eb03903e63e2cc4 to your computer and use it in GitHub Desktop.
Webflow Form Submission for Loops
<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