/before.js Secret
Created
April 29, 2022 15:00
Revisions
-
askkaz created this gist
Apr 29, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ <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>