AJAX form submission to Webflow server

Our Webflow site integrates third-party services, so we have customers that come back from a third-party site to a certain Webflow landing page. When this happens, we want to save this event into our Webflow form submissions.

We use a custom JavaScript (inside an HTML embed symbol) that stores user data inside the browser’s localStorage before the user leaves our site. Technically, our script overrides the default (made in Webflow designer) form’s onsubmit event without preventing the default form submission. The form’s redirect URL makes Webflow redirect the user to the third party.

Now we have form submission data about the user, but we do not know yet, if they will complete the third-party action. This is why we will need another submission once they have returned to our site.

Our landing page for returning customers checks if there is any user data stored in localStorage, and if there is, we create a form element with hidden input fields populated with the stored values. The form behaves like a regular default Webflow form, with the redirect URL set to # (maybe this should better be window.location.pathname?) After creating the form and appending it to the document body, we trigger its submit function.

All of the above is achieved using JavaScript, it works, but not in an elegant way.
1.) Form submission causes a visual site reload.
2.) The redirect URL contains the form values, as we have to use GET (tried POST and got a method not allowed error from Webflow’s server).
3.) Submit has no callback, so error handling is currently missing (and might be a hack to implement).

All issues could be resolved by using AJAX to submit the form data to Webflow silently in the background, and use proper callbacks to verify if the data has been sent, so we can either delete localStorage or retry sending.

I did not find an API documentation for frontend JavaScript customization yet, maybe there is already a perfect solution hidden inside the Webflow object.

Maybe I am just overthinking the problem and looking into the wrong direction. If this can be achieved with default designer settings, that would even be better.

1 Like

I’m curious about this, too.

Did anyone find out if that’s possible to integrate asynchronous requests with AJAX, eventually? I’m guessing this is what the question is?

Hey Samuel,

We built a tool to solve the issue of calling APIs from the Webflow frontend (including the Webflow CMS). The application is called MiddleLink (https://www.middlelink.io).

Here’s a handy link if you’re looking to make an Ajax request using jQuery + Webflow form.

Let me know if you have any specific questions. I am happy to help. :smiley:

I think you can skip some of the steps. See when a form submission happens, it just makes an HTTP call to the Webflow’s URL, which you can get from the designer.

So you don’t need to create a form HTML element. You can just directly use JavaScript to make a form submission POST call to send all the data to the Webflow form endpoint.