Google Sheets integration
Learn how to read and write data to and from Google Sheets.
Save form responses in Google Sheets
Follow the steps below to save blocks.md form responses in your Google Sheets. Let's use the following example:
So we have three fields: email
, products
, and budget
. Please note, the >> post
will partially submit the form after the first slide (so that the email is captured immediately).
0. Quick video guide
Here's a quick video guide if you don't feel like reading:
1. Set up a Google Sheet
The first step is to set up a Google Sheet so that the first row (headers) match the names of the form fields you want to save.
There are three other fields which are sent automatically:
_rid
—unique ID of the response_submitted
—date and time when the response is submitted_end
—whether or not the user has reached the end or not (in case of partial submissions, this will not be TRUE)
2. Create a Google App Script
Click on Extensions -> Apps Script
. This will open a new Google Script. Rename it to something like blocksmd-form
.
Replace the myFunction() { ... }
section with the following:
Save the project before moving to the next step.
3. Deploy the project
Click on the Deploy -> New Deployment
button on the top right corner of the screen. A modal will open up. Select Web app
from the dropdown (open the dropdown by clicking on the settings icon on the left hand side).
On the next screen, select the following options:
Web app → Execute As:
Me
Web app → Who has access:
Anyone
After that, click on Deploy
.
On the next screen, you will need to give the project the proper permissions by clicking on the Authorize access
button.
Another pop-up will open up on the screen. Select the correct Google account (the one you used to create the Google Sheet and App Script).
The next screen will generate a warning before you can continue. This is actually totally safe because you know exactly what code you're running. You must click on Advanced -> Go to blocksmd-form (Unsafe)
for the script to have the correct permissions.
On the next screen, click on the Allow
button to give the project the required permissions.
You should see a successful deployment. Copy the Web app URL
from this screen and keep it with you. We need to add it as a setting to our form.
4. Run the initialSetup()
function
initialSetup()
functionAfter the deployment, close the modal. Next, you need to run the initialSetup()
function by clicking on the Run
button. Make sure this function is the one selected.
Please note, at this point, you may need to Review permissions
again. In that case, follow the steps as above:
Select correct Google account
Advanced -> Go to blocksmd-form (Unsafe)
Click on
Allow
button
5. Add the Web app URL
as a setting
Web app URL
as a settingFinally, set the URL you copied from the deployment modal as the value for the post-url
setting:
And that's it. You should be able to save your form responses directly in your Google Sheet now!
6. See the form in action
Here's a video of the form in action:
7. Change the sheet where the response is saved
By default, the response is saved in the very first sheet of the document. However, you can specify which sheet to save the response in by putting the name of the sheet as the value of the post-sheet-name
setting. For example, #! post-sheet-name = Sheet2
would save the response in Sheet2
.
Full documentation: Send responses
Read data from Google Sheets
Please note, a Google Sheet that has been published to the web can essentially be read by anyone. This is totally fine as long as it contains data that you want to make public. In general, it is highly recommended that you use one sheet for saving form responses, and another sheet for reading data.
You can also easily prepare a Google Sheet so that your forms and pages are able to read its data and use it on the template. In order to do this, go through the following steps:
Open the Google Sheet
Click on
File -> Share -> Publish to web
from the top menuA modal will open up: select the sheet you want to publish and change
Web page
toComma-separated values (.csv)
orTab-separated values (.csv)
Click on
Publish
and confirm the actionCopy the URL that is shown on the screen
All you need to do now is set this URL in the #! get-url = {url}
setting. If you're reading TSV, then also set #! get-format = tsv
.
For example, here's a Google Sheet we want to read:
Full documentation: Set and read data
Last updated