The components involved in this workflow are:
- A script to generate and send an email with an HTML form.
- An html template for that email, which allows us to customize the email for each recipient.
- A
doPost()
function to handle responses. The script must be deployed as a Web App. - A spreadsheet to collect responses. The script will be contained in the spreadsheet, and extends the spreadsheet UI with a menu for sending a copy of the survey. (It could be adapted for standalone use, without the UI component.)
Here is an example of such a workflow, conducting a Commuting Survey. Recipients will receive a survey email like this:
Recipients fill out the form right in their email client, if it supports that capability. Responses will be collected in a spreadsheet, like this:
Create the spreadsheet headers yourself, before running the script.
The "Serial Number" column has been added to illustrate a way to correlate responses with particular respondents; note that some entries repeat. When a survey email is generated, it is given a unique serial number, which is then passed back as a hidden value with the responses. We could extend this system to recognize updates from respondents, for instance.
For users without appropriate HTML FORM support in their clients, links are provided in both plain text and html versions of the mail.
To use this survey system as-is:
- Create a new spreadsheet in your Drive account. Add headers for "Timestamp", "Serial Number", "Commuter?", and "Vehicle" in row 1.
- Tools - Script Editor. Copy the
Code.js
content. Copy the ID of your spreadsheet, and update the_spreadsheetId
variable at the top of the file. Save. - File - New HTML file, name the file emailTemplate. Copy the
emailTemplate.html
content. Save. - Publish - Deploy as Web app... Make it accessible by anyone, including anonymous. (In a Google Apps domain, you can restrict it to users in the domain.)
- Authorize the script, by reloading your spreadsheet or running the
onOpen
function in the editor.
Ready to go! You'll find a "Custom Menu" in your spreadsheet, with a "Send Survey" command.
Fingers crossed you are still around:
I've implemented this and it works well except that when the alternate online form is submitted an error loads. For chrome it says "script.googleusercontent.com refused to connect.". On Firefox it says "Firefox cannot open this page with a this link to learn more.
Most of the correct info still gets passed to the sheet (except the serial code), but the error itself makes it hard to distribute to clients.
To make the serial number meaning full I swapped out the GUID generator within getGUID and just input in a string for the name of the person I'm sending the email too. It works perfectly when submitting the embedded form but when the pop up form is submitted a new GUID is generated and inputted into the cell instead. I'm not even sure where it is coming from because I removed the GUID generator. Even in testing when I returned it the number that comes back is different than the one that went out. Is it possible to address this issue so I can have identifiable date from submissions?
I got it a few minutes after I typed this. Needed to deploy a new version of the app not just update the current.