automated petition signatures with google forms

Since the graduate student strike and related protests by faculty, staff, and undergraduates at the University of Michigan in Fall 2020, I’ve noticed that open letters and petitions in google docs and signed through google forms seem to have replaced slower, more traditional petition technologies for (at least campus) social movements. Having signatures from a google form automatically and instantly appear at the end of an open letter is pretty straightforward, but I wasn’t able to find a good guide for it. So in the “unruly sociologist” spirit of this blog, here is my lay person’s guide to automatic signatures in a petition using google docs and forms.

First up, a cautionary point. When you put a form up on the internet and share the link around, people can and will type all kinds of vile, racist slurs in it. If you make the things people submit to a form automatically appear on a public document, you’re likely to see the n-word among the signatures to your petition. Some ways around this.

  1. If you’re at an institution that has google accounts (like many universities and some companies), you can restrict the people who sign the form to people from your institution in the google form settings. Bye bye outside trolls. (And hello risk of institutions locking you out of your account for criticizing them. Looking at you, Jeff Dean.)
  2. No matter where you are, you can require people log in with their google account in the form settings. This records their email address, and that discourages bad behavior.
  3. You can share the link to the form only in trusted circles (email lists, closed groups, etc.).
  4. Regularly check the signatures for abuse.

Okay, so you’ve decided how you’ll avoid abuse. Now the fun part. Write up your petition or open letter in a regular google doc. Then make a google form asking for people to sign it. It is a good idea to include a link to the form in the doc, and a link to the doc in the form. The example code I’ll use in this demo assumes that the very first question in the form is their whole signature as they would like it to appear in the petition. It is also a good idea to let people answer the form more than once. This lets you test it before making it public, and it lets a person submit multiple signatures (e.g. for people who say “add my name” but don’t want to or cannot do it themselves).

In the form, click “Responses” and then the little green “Create Spreadsheet” square near the top right. Then open the spreadsheet. Click “Tools” then “Script Editor.” Paste the code below into the editor. Be sure to use the whole thing and replace the little example “myFunction()” part that is in there by default.

function appendSignatureRow(e){
  //Since there could be a bunch of people submitting, we lock the script with each execution
  //with a 30 second timeout so nothing gets overwritten
  const lock = LockService.getScriptLock();

  // Here we read the variables from the form submission event
  // we're assuming the first question in the petition is their signature as they want it to appear
  // the number here is the column in the spreadsheet, column A = 0, column B = 1, column C = 2...
  const name = e.values[1];

  // you could also use multiple questions / columns from the spreadsheet, like this
  const title = e.values[2]
  const department = e.values[3]
  //Next we open the letter and get its body
  const letter = DocumentApp.openById('yourPetitionDocIDHere');
  const body = letter.getBody();
  // if you have the whole signature in just one question, use this code
  const sig = name 

  // if you want to make a signature by combining several questions / columns from the spreadsheet, use this
  // remove the two slashes before the line of code below this to use it instead 
  // const sig = name + ", " + title + ", " + department


  //here we save and close our letter and then release a lock 

Replace the part that says “yourPetitionDocIDHere” with the google document ID of your petition. Remember to keep the quote marks around it, though. You can get the document ID from the URL of the google doc. So if the URL is this, , then the document ID is the gibberish part near the end, “1pZkn0IknVTkFIHAbAd8DOchzjeF8p5xE”.

After you replace the document ID, click the little clock icon on the left that says “Triggers”. Then click “Add Trigger” in the bottom right. It should look like the example image: the function to run is “appendSignatureRow”, deployment is Head, event source is spreadsheet, and event type is “on form submit”. Save it.

Now go to your form and test it out with a signature. Give it a second, then see if it pops up right. Note that if you’re seeing an email address or date or something else instead of the signature, you’ll want to change the number in line 12 of the code. Those numbers are which column of the spreadsheet it uses, so you just need the right column number to see the right data.

Once the signature form is working, you’re ready to share your petition! I suggest that you don’t just give out the google doc link, though. If a bunch of people all view that at once, it will be slow for everyone. Instead, in the google doc, go to “File” then “Publish to the web” and then “Publish”. Copy and share the link it gives you, and you’ll never have issues with too many people viewing it at once. Happy rabble rousing.

Note: I borrowed from Jeff Everhart’s blog posts to make this code. They may be helpful to you as well. But his examples are a bit more complicated and designed for different use cases, so it wasn’t obvious how to get to the use case many campus social movements have.

Author: Jeffrey Lockhart

Jeff is a PhD Candidate at the University of Michigan, writing his dissertation on the scientific debates around biological sex essentialism. He tweets @jw_lockhart.

5 thoughts on “automated petition signatures with google forms”

  1. Thank you soooo much for this. It worked! It was relatively easy and painless and it enabled me to do just what I wanted to do. – Michael D


    1. Super helpful, thank you! Two things were different in my google docs interface. First, I found the script editor under “Extensions > Apps Scripts” rather than under Tools. Second, I don’t see an option for “File > Publish to the web > Publish.” I only see the option to “Send form” and then copy the URL given in that box.


      1. Glad it was helpful! Publishing to the web is for sharing the letter/document, not the form, in case that helps. You’re right about the form buttons, though!


  2. Hi – I’m having issues getting it to work in the new apps script editor in google. Do you take out the first line in the script editor? It said something about ‘thisdocument only’


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: