Jump to content

Redirect to another page in my site after submitting a form?

Recommended Posts

  • Replies 23
  • Created
  • Last Reply

The following code seems to work. Replace “/” with the relative link you want the redirect to go to. If you want to link to an external site you’ll need to enter a full url of the format

http://www.somewhere.com/somepage.htm

The code should be inserted in the injection point for the form page:


<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var eventposted = 0;

$(document).ready(function() {
 $('input.button').click(function() {
   window.setInterval(foo, 100);
 });
});

function foo() {
 if (($(".form-submission-text").is(':visible')) && (eventposted == 0)) {
   window.location.href = "/";
 }
}
</script>

If you're looking for a Squarespace Developer, drop me a line. 

Link to comment

Thanks! I inserted it just as you said, and it works.... sort of.

When I fill out the form, it still takes me immediately to the same thank you message, but it'll simultaneously try and slowly load the linked page (which is my blog page.) You can actually watch the little 'loading page' wheel on the website tab in the browser (I'm using Chrome) - it spins and skips a few times (it looks kind of glitchy) and then after about 15 seconds of that, it loads the page.

I've tested it about 4 times and it's doing the same thing each time. All the rest of the pages are loading just fine, without hesitation. It's just this one redirect that is lagging. Any idea what may be causing this?

Thanks again for your help!

Brooklyn based freelance graphic designer, and SquareSpace enthusiast.

Link to comment

You'd expect it to load the thank you message, because the redirect only happens once the DIV that holds the message becomes visible.

When I tested it on my site there was a gap of a second or so before the redirect happens, I can't think of any reason that the code would be responsible for any delay.

If you're looking for a Squarespace Developer, drop me a line. 

Link to comment

Thinking laterally.. ..why not change the Thank you message to set the user's expectations:

"Thanks for getting in touch.. ..you will be automatically redirected to my blog page in a few seconds. To get there quicker, click this link... "

If you're looking for a Squarespace Developer, drop me a line. 

Link to comment
  • 2 months later...
  • 2 months later...

Here is a better fix for you, this works every time for me! Simply replace "YOUR URL HERE" with your URL.


<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">  
   var eventposted=0;  
   $(document).ready(function(){
       $('input.button').click(function() {
           window.setInterval(foo, 100);
       });
   });
   function foo(){
           if(($(".form-submission-text").is(':visible')) && (eventposted==0)){
             eventposted = 1;
             window.location.href = "YOUR URL HERE";
           }
   }
   </script>


Link to comment
  • 2 months later...
  • 1 year later...

The code I posted was written before the light box form option existed. I'll have a look at making a script that works with both form types (and maybe add to cart) bit it's going to be sometime next week before I'll have time to work on it.

I need it for a couple sites - one of mine and a client's site - so it will definitely get done sooner rather than later.

If you're looking for a Squarespace Developer, drop me a line. 

Link to comment
  • 1 month later...
  • 2 months later...
  • 11 months later...
  • 1 month later...
  • 1 year later...

@silvabokis has the right code. I discovered that if you are using your form in a lightbox within an index you need to apply his code in the code injection space in the main settings or inside the site.region file if you're in developer mode.

This twist on his solution wouldn't work if you have various forms throughout the website that all need their own redirect page. I'm using this for conversion tracking and retargeted advertising, so I'm just redirecting every form submission to www.mybaseurl.com/# and inputting that as my "converted" url.

Raise Capital Faster: Reaching More Investors with the Power of Technology

Link to comment
  • 8 months later...
  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.