GDocs Display blank form after submit

Redirects back to empty form after displaying the confirmation message for 5 seconds

< Feedback on GDocs Display blank form after submit

Question/comment

§
Posted: 2018-10-10

Script Question

// ==UserScript== // @name GDocs Display blank form after submit // @version 0.2 // @description Redirects back to empty form after displaying the confirmation message for 5 seconds // @author Melgior // @match https://docs.google.com//formResponse // @grant none // @namespace https://greasyfork.org/users/5660 // ==/UserScript==

if (document.getElementsByTagName("form").length === 0) { setTimeout(function(){ document.location = document.location.href.replace("formResponse", "viewform"); }, 5000); }

Do I put this code in the google sheets script or do I enter it in the form. Do I need to rename the tagname"form" to the name of my form?

MelgiorAuthor
§
Posted: 2018-10-10

Hi Eric, this script is a userscript and not a Google Apps Script. You can run it by installing a browser extension and then add the script to the extension. I see you're using Google Chrome, here's a link to an extension that supports userscripts: https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo

Once you've installed the extension you can use the install button on my script's homepage to install the script. You don't have to rename anything in the script, it will automatically apply to all your forms.

§
Posted: 2018-10-11

Thank you for taking the time to respond. Works well. Since I have my hand out I am wonder if there is an easy way to handle google forms that have prefilled answers with your script.

For instance I modified your script as seen below for a test form and the prefilled answer "JSA TEST did show up on the form. Wondering if there is a way to use wild cards. I would be using forms that have different answers prefilled and would have to manually modify the script each time..

document.location = document.location.href.replace("formResponse", "viewform?entry.1901372887=JSA+TEST");

§
Posted: 2018-10-14

Figured it out through additional searches. Wrote a separate script to capture the prefilled data and passed the variable "s3" through to your script. Here it is if someone else needs to do this.

// ==UserScript== // @name GDocs Get Prefilled Items // @version 0.1 // @description Copies the viewform prefilled elements to local storage // @author Estelle // @match https://docs.google.com//viewform // @grant none // @namespace https://greasyfork.org/users/5660 // ==/UserScript==

var regex = /^(https?:\/\/)(.+)viewform(.+)$/i; var s3 = document.location.href.replace(regex,'viewform$3'); localStorage.setItem("s3Key",s3);

Post reply

Sign in to post a reply.