Here is how to use it
- Create a form as you normally would. The only caveat here is that currently you can not use spaces in the form Question Titles (column names).
- Search the Gallery for FormSubmissionResponseEmail and install it into your spreadsheet. (Tools -> Script gallery . . .)
- Configure the script to execute when the form is submitted. Do this by opening the script in the script editor (Form -> Script editor ...) and then setting up a trigger (Resources -> Current script's triggers). Set formSubmissionResponseEmail to run when the form is submitted.
- Add a new sheet to your spreadsheet, on this sheet you will define 4 named ranges;
- FSREAdministrator - administrator email address
- FSRERecipientCol - the column number of the submitter email address
- FSREContent - the key of a document containing your template email
- FSREWhiteList - the key of an optional spreadsheet containing your email white list
- Create your template email message as a new document. Use your column names in brackets as placeholders for your replacement text (e.g. [Timestamp])
- Get the key of this document and add it to the named range in your form spreadsheet.
- Optionally add the key of your white list spreadsheet to the named range in your form spreadsheet.
Here's how it works
When your form is submitted, the spreadsheet triggers the script and passes it the new data. This means that unlike the previous example multiple submissions can be processed simultaneously. The script does some error checking and then opens up your template email and replaces the text with the data from the form.
If you have provided a white list the script will ensure the recipient is on the whitelist, otherwise the mail will be sent to the administrator. The original recipient and a note that they are not white listed will be included in that message.
Named Ranges in Spreadsheets
Variables for the script are provided in named ranges. This eliminates the need for you to edit the script and means the same code can be used for multiple forms. To define a named range in a spreadsheet highlight a cell or range and go to Insert -> Named range -> Define new range ...
For the four script variables in your form spreadsheet only the first cell is used no matter the size of the range. To create a range in your white list spreadsheet it is easiest if you select entire rows or columns to define your range. You may need to update your white list range if your white list grows in size.
Document Keys
There are two parameters that use document keys to identify documents in your Google Docs account. The first is for the email template. The second is the optional white list spreadsheet. There may be a better way to find the key, but you can find it by opening the file and looking at the URL in your browser's address bar. The key is the parameter to the URL, the highlighted section in the example.
https://.../spreadsheet/ccc?key=0AmuBOD8EcgrfdxaQm5SkJXTnYwT2VYcUE#gid=0
White List
Since you are essentially building an open email portal the white list will protect you from scripts using your form to blast out spam. In a future version the script will be able to access a contact group for the white list. For now the white list is a separate spreadsheet with a named range "WHITELIST" containing all valid recipients. You can leave the white list off and you can use the same white list for all your forms.
Resources
A collection of files for a sample app is available. Included in this collection is the source code for the script. It may take some time for the script to show up in the gallery, if you can not find it in the gallery simply cut and paste this code into the script editor window.
Sample
A working sample, using the files shared above, is available here. Please be aware that any content you supply including email addresses will be visible to others. I have disabled the white list so that you can receive responses.
Thanks very much for this! Was very handy in getting a slick rego form with confirmation email together at short notice.
ReplyDeleteThanks Steve - very helpful and very kind of you to post this. A good comprehensive set of files and instructions - I was successful yesterday:-)
ReplyDeleteSmall pointer: The column number for the email address is programming notation - ie starts at 0 so that column A is actually column 0 not 1!
I must be too thick to understand what you are doing with the whitelist - it seems to me if you make use of this then this will mean that only people on the whitelist will be able to get an email sent to them - that could be really helpful for another application I'm thinking of but I haven't tested that yet.
K