Hey Webflow folks! I’m currently looking for a JS solution to catch successful form submissions to then redirect to a custom link (in this case I’m carrying query params). I’ve seen a couple of threads which skirt around the issue but Webflow’s implementation appears to have changed recently, blocking some of the older methods used.
I’ve been able to get timeouts to work after initial submission by using the following code (please forgive the params bit):
var Webflow = Webflow || [];
Webflow.push(function () {
$('form').submit(function (event) {
setTimeout(function() {
var url = window.location.search;
var $params = url.split("?")[1];
window.location.href = "{URL HERE}"+$params;
}, 1000);
})});
One thread mentions using AjaxComplete, but this doesn’t seem to work (if anybody has a working example with AjaxComplete that would be amazing). I’m specifically looking for a success event here, since with the timeout implementation a user could fail to submit yet still be redirected (I’m imagining that all of my users live in a rainforest with poor internet).
Thanks for the help in advance! (I haven’t included a share link for now since there aren’t any selected elements in it. If anybody would like it anyway please feel free to ask!)
@Jack_Howell - I don’t think Webflow provides any default callbacks for successful form submissions. But, you might be able to trigger your code to fire when the default success message block is shown (ie when a css property change is detected on the success block.
I believe the element has the w-form-done class on it.
Thanks both so much! I’ve managed to get it running with AjaxComplete now. For whatever reason jQuery had to be loaded async in the head tag rather than before body . All fixed now!
Aha! For whatever reason I’d had an issue ages ago where JQuery didn’t seem to load hence I’d been loading it manually since. Removed and it worked! Thank you!