Jump to content

Refresh form after submission without reloading the page

Recommended Posts

Posted

Site URL: https://www.joyrx.org/livestream-live

I have added a very simple form block to a page of my site. The form only has one field — to enter a simple text message — with a "submit" button (see screenshot below).

image.png.7eeebec655065ce5703786fb2cb8edd7.png

I'm looking for a solution that allows users to type a message, submit the form, and have the form auto-refresh without having to reload the page. Basically, I need users to be able to submit the form multiple times without reloading the page. Is there a solution for this?

I have tried adding the following script to Website Tools > Code Injection > Footer:

<script>
  $('button[type=submit]').on('click', function () {
  checkSubmitSuccess($(this).parent().parent())
});

function checkSubmitSuccess(formElement) {
	console.log(formElement)
  var i = 0;
  while (i < 10) {
    (function (i) {
      setTimeout(function () {
        if ($(formElement).hasClass("react-form-contents--submitted")) {
        	console.log("Hereee")
          i = 10
          window.location.reload()
        }
      }, 1000 * i)
    })(i++)
  }
}
</script>

This script is not working for me. It looks like I'm getting a syntax error (see screenshot below). I'm not sure how to fix this to get it to work (refresh the form on "submit," not the page). 

image.png.5277ea0e3874563afa1493559bfd2be4.png

Any help would be very much appreciated!

  • Replies 0
  • Views 412
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Posted Images

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.