Created
April 17, 2018 20:16
-
-
Save laradevitt/fbd0ba66fe6776b446ac6e305dee701c to your computer and use it in GitHub Desktop.
A super simple Google Apps Script app that loads a different version of a Google Form, depending on URL parameter. The alternate version hides a text field and populates its value with the value of the URL parameter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doGet(e) { | |
// The file that will be loaded into the template. | |
var file = 'index'; | |
// The 'secret' value, optionally passed in via URL. | |
var secret = ''; | |
// If parameter 'secret' is set, specify an alternate file to load into the | |
// template and prepare to pass the 'secret' value on. | |
if (typeof e.parameter.secret != 'undefined' && e.parameter.secret.length) { | |
file = 'index-2'; | |
secret = e.parameter.secret; | |
} | |
// Use the HTML Service to create a template from a file in the code editor. | |
var result = HtmlService.createTemplateFromFile(file); | |
// If secret contains a string, pass on its value to the template. | |
if (secret.length) { | |
result.secret = secret; | |
} | |
return result.evaluate(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
<title>Form 2</title> | |
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> | |
</head> | |
<body> | |
<h1>Form 2</h1> | |
<form action="https://docs.google.com/forms/d/e/1FAIpQLSe_vSviObTgVujebAGHk5kFhF7xoOG_clP86gOy9bVkLaBflQ/formResponse" target="_self" method="POST" id="mG61Hd"> | |
<div class="block form-group"> | |
<label for="name">Name</label> | |
<input id="name" type="text" tabindex="0" aria-label="Name" name="entry.1109311124" value="" dir="auto" /> | |
</div> | |
<div class="block form-group"> | |
<button tabindex="0" type="submit">Submit</button> | |
</div> | |
<input type="hidden" aria-label="Claim your prize" name="entry.707882927" value="<?= secret ?>" dir="auto" /> | |
<input type="hidden" name="fvv" value="1"> | |
<input type="hidden" name="draftResponse" value="[null,null,"-608993261238617425"]"> | |
<input type="hidden" name="pageHistory" value="0"><input type="hidden" name="fbzx" value="-608993261238617425"> | |
</form> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
<title>Form 1</title> | |
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> | |
</head> | |
<body> | |
<h1>Form 1</h1> | |
<form action="https://docs.google.com/forms/d/e/1FAIpQLSe_vSviObTgVujebAGHk5kFhF7xoOG_clP86gOy9bVkLaBflQ/formResponse" target="_self" method="POST" id="mG61Hd"> | |
<div class="block form-group"> | |
<label for="name">Name</label> | |
<input id="name" type="text" tabindex="0" aria-label="Name" name="entry.1109311124" value="" dir="auto" /> | |
</div> | |
<div class="block form-group"> | |
<label for="prize">Claim your prize</label> | |
<input id="prize" type="text" tabindex="0" aria-label="Claim your prize" name="entry.707882927" value="" dir="auto" /> | |
</div> | |
<div class="block form-group"> | |
<button tabindex="0" type="submit">Submit</button> | |
</div> | |
<input type="hidden" name="fvv" value="1"> | |
<input type="hidden" name="draftResponse" value="[null,null,"-608993261238617425"]"> | |
<input type="hidden" name="pageHistory" value="0"><input type="hidden" name="fbzx" value="-608993261238617425"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment