Redirect after submitting Google Form
Asked Answered
S

2

7

I have a custom Google Form i made and an own site. What i need is, after submitting the Google Form, to allow the user access to download a file. This means that you should only be able to access to file if you completed the form.

I have been looking for a way to redirect to a custom URL without showing the URL (so the user cannot copy-paste it and download the file many times) but it is impossible to redirect after the submission (even if the form is embedded).

I even tried to make the form open a pop-up with the file url or something but everything seems impossible to do.

Is there a way to achieve this?

Sable answered 4/7, 2018 at 20:27 Comment(3)
No, there is no way to redirect to another URL after a Google Form is submitted. You'd need to use a Web App with an HTML form. You can put an Apps Script Web App into an html iframe tag, although you may get cross domain errors if you do that. Or you can just put an HTML form into your site, with no Web App, and make a POST request to a stand alone Apps Script file. The Apps Script file needs a doPost(e) function. Send the answers in the POST payload. I'm assuming that you can put JavaScript into your site, which can do whatever you want.Phifer
Send an email in the response that contains a temporary, one-time-use link to the web app with a unique URL parameter. When you generate the URL, cache that parameter for the desired time limit (1s to 6h) and remove it upon serving the file.Showmanship
@Showmanship this solution resolves quite good what i need, i will search how to do this.Sable
N
15
<!-- Normal form embed code, add an ID -->
<iframe id="gform" src="https://docs.google.com/forms/d/e/1FAIpQLSeaiWCc598b3beFhYraf4nNsLgG3bXby_Qne93rHy_Mb_8UIA/viewform?embedded=true" width="640" height="487" frameborder="0" marginheight="0" marginwidth="0" style="margin:0 auto; max-width:100%;">Loading…</iframe>

<script type="text/javascript">
var load = 0;

document.getElementById('gform').onload = function(){
    /*Execute on every reload on iFrame*/
    load++;
    if(load > 1){
        /*Second reload is a submit*/
        document.location = "https://www.google.com/search?q=thanks&tbm=isch";
    }
}
</script>
Nootka answered 28/1, 2019 at 16:50 Comment(3)
Description in comments! :PNootka
This doesn't work with multi-page google forms, especially in those that can let you submit in the middle.Mulkey
I tried this code but it doesnt work always.. not sure why? out of 4 attempts it only worked once..Chukker
B
0

If your embedded form is loaded with a script and the webform can have a redirect on submission i found this answer that worked for me:

This is really a very old thread but if someone needs then can do following workaround:

  1. Create a new HTML page say 'test.html' which will have only code in script tag like as below, please change your HTML page name to final page name in the following code:

    window.parent.location.href = 'final.html';
  2. In Webform form submission setting please redirect the user on above HTML page

So now when the form submits Podio will redirect to the above temporary HTML page and the temporary page will reload the main parent page with the correct HTML page.

https://help.podio.com/hc/en-us/community/posts/212217608/comments/360001462172

Bactria answered 13/3, 2023 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.