Submit Old Google Form then redirect to another page

I am using a Google form on a web page. I copied the source code from the form directly to my page so that I can modify part of the HTML instead of using an iframe. Then, instead of introducing the user to the answer page with Google docs, I would redirect them to another page.

The problem that I am encountering is with the reconfiguration of the page. I was able to work fine 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 automatically redirected and the response was never written to the Google form. If I drop the redirect, the action works fine in both cases, and the response is written to a Google spreadsheet.

So, I tried to pull the action and instead did everything in onsubmit, like this:

 <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"> 

The same problem as before, IE and Safari are redirected, and nothing is written to the Google spreadsheet. And again, if I remove the redirect, the response will be recorded in all browsers. I can also do other things, for example, throw a warning after an action, and everything continues to work fine. The only time I see a problem is a redirect.

Thus, at this moment I can only understand that this is some kind of conflict between redirection and action. I have fairly limited knowledge of javascript and forms, so any help or recommendations would be greatly appreciated!

+12
javascript html google-spreadsheet google-form google-sheets
source share
1 answer

It appears that the browsers did not complete the form submission before processing the redirect. onsubmit occurs before the submission itself, so you cannot solve the problem there.

Use the onload function for the target iframe to redirect.

This is set in a similar way:

Old Google form redirect after submit

Take a look at the answer. The onload iframe function will handle the redirect, so the redirect will not happen until the view is complete and the response is sent from Google. Therefore, when the hidden answer from google is loaded, we start the redirect. This is asynchronous functionality between client and server. We expect the server to process the data before being redirected.


Extended Note. You can try to redirect the setTimeout function. This delays the redirect, allowing the server to process the request first. But setTimeout requires a fixed amount of time, so if the data processing is not synchronous (i.e., Asynchronous), setTimeout will not work, because it can fire earlier or too late. Asynchronous data processing is used when data processing requires an indefinite period of time (for example, HTTP requests).

0
source share

All Articles