How to refresh page on form submit (for only one form)

How do assign this function to one specific webflow-form on a page correctly?

Form class: dashboard-form

do you wrap it in? → If ( $(“.dashboard-form”)) {}

<script>
Webflow.push(function() {
  $(document).on('submit', 'form', function() {
    // Refresh page after 1000 milliseconds
    setTimeout(function() { location.reload(true); }, 1000);
  });
});
</script>

Hey @HappyDigital,

You’re super close. Just need to assign an ID to the form element and change your code from $(document).on… to $('refreshThis').on… where the refreshThis ID is added to the form element itself.

The code would then be:

<script>

var Webflow = Webflow || [];
Webflow.push(function () {

    $("#refreshThis").submit(function (event) {
        setTimeout(function () { location.reload(true); }, 1000);
    });

});

</script>

I created this cloneable project for you (and others) to see how it’s done. Hope it helps!

5 Likes

Hi Mattvaru!

You’re the best! Thanks for reaching out, much appriciated!

Cheers!

1 Like

Hey @mattvaru

Thanks for making this cloneable for us, that’s exactly what I was looking for, however I’m facing the problem of page being refreshed too fast even before the form was submitted. I know I can increase delay time but I don’t think its clean solution. Is there away to refresh only after form was successfully submited?

2 Likes

A perfect solution, used this on a project I’m working on and it was so easy to implement and flawless execution. You’re a saint, sir.

Hey I appreciate this! Where do I place it? I can’t see any custom code blocks in the header of your website or body.