Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit Old Google Form then redirect to another page

I am utilizing a Google Form on a webpage. I copied the source code from the form directly onto my page so that I can modify some of the HTML instead of using an iframe. Then instead of taking the user to the google docs response page I would like to redirect them to another page.

The trouble that I am running into is with the page redirect. I was able to get this working properly in Chrome and Firefox with this:

<form target="GoogleResponse" action="https://docs.google.com/spreadsheet/
formResponse?formkey=xxxxxxxxxxxxxxxxxxxxxxxxxx&amp;ifq;" onsubmit="
window.location = 'targetPage.html';" method="POST" id="ss-form">

IE and Safari both did the redirect automatically and the response never got written to the Google Form. If I drop the redirect, the action works perfectly in both and the response is recorded in the Google spreadsheet.

So I attempted to pull the action out and instead did it everything in onsubmit instead, like so:

<form target="GoogleResponse" onsubmit="this.action = https://docs.google.com
/spreadsheet/formResponse?formkey=xxxxxxxxxxxxxxxxxxxxxxxxxx&amp;ifq'; 
window.location = 'targetPage.html';" method="POST" id="ss-form">

Same problem as before, IE and Safari both redirect, and nothing is written to the Google spreadsheet. And once again, if I remove the redirect the response gets recorded in all browsers. I can also do other stuff like throw in an alert after the action, and everything continues to work fine. The only time I see the issue is with the redirect.

So at this point the only thing I can figure is that their is some sort of conflict between the redirect and the action. I have pretty limited working knowledge of javascript and forms so any help or recommendations would be greatly appreciated!

like image 288
strangiato Avatar asked Mar 16 '12 05:03

strangiato


People also ask

What happens to your previous response if you submit another in Google Forms?

Recommended Answer If you hadn't hit submit, you'd be able to see the work you'd already done when visiting the link again, as Google Forms automatically saves responses in unsubmitted Forms. You can also double check with the form owner to be sure. Learning with Laurah J.


1 Answers

Sounds like the browsers have not complete the form submission before handling the redirect. onsubmit happens before the submission itself so you can not handle the issue there.

Use the onload function of the target iframe for the redirect.

This has been asked in similar manner:

Old Google Form redirect after submission

Take a good look at the answer. The onload function of the iframe will handle the redirect, so the redirect will not happen until the submission is complete and a response has been given from google. So when the hidden response from google is loaded we fire a redirect. This is async functionality between the client and server. We are waiting for the server to handle the data before redirecting.


Extended note: You could try putting the redirect within a setTimeout function. This would delay the execution of the redirect, allowing the server to handle the submission first. But setTimeout requires a fixed amount of time, so if the data handling is not synchronous (ie. asynchronous) setTimeout will not work as it may fire to early or too late. Asynchronous data handling applies when the data processing requires an undetermined amount of time (such as http requests).

like image 122
mmm Avatar answered Sep 28 '22 05:09

mmm