<aside> đź’ˇ

This article is out of date - a redirect can now be added simply by entering your thank you page URL in the box on your form’s Advanced Tab:

image.png

</aside>

Redirecting to a Thank You page works slightly differently in each of these scenarios:

In both scenarios you’ll add code to your form.

In scenario 2 only, you’ll also add code to your website.

Code for your form

Paste the following snippet to your form’s Advanced tab in the Code end body section.

Replace https://www.example.org/thankyou in this code with your Thank You page’s URL.

<script>
  document.addEventListener(
    'checkoutSuccess',
    function () {
      var url = '<https://www.example.org/thankyou>';
      if (typeof embedded != 'undefined' && embedded) {
        window.top.postMessage({redirect_url: url}, window.hostOrigin || window.hosts[0]);
      } else {
        window.location.href = url;
      }
    },
    { once: true }
  );
</script>

This code contains a function that will run after a user completes the checkout process (when the checkoutSuccess event occurs).

When the function runs, it checks to see if the form is embedded.

If the form isn’t embedded, the function redirects to the Thank You page URL immediately.

If the form is embedded, the function posts a message to your website containing the Thank You page URL.

Code for your website (only if embedded)

Paste the following code before the form embed code on your website:

<script>
	window.addEventListener(
		'message',
		function (event) {
			if (event.origin == '<https://cms.smartraise.net>' && event.data && event.data.redirect_url) {
				window.location.href = event.data.redirect_url
			}
		}
	);
</script>

*<!-- Your form embed code here... -->*

This code contains a function that will run after a message is received from the form.

When the function runs, it checks to see if the message contains a redirect URL and if so, it redirects the user’s browser to the URL.