Uses Google Apps Scripts with Google Sheets to provide a POST endpoint for form data that is parsed into sheet fields.
https://techcoop.github.io/form-google-sheets/
- Google Account
- Google Sheet with column headers
- node > 6.0.0 (Optional)
- yarn (or npm latest) > 0.10.0 (Optional)
- Create a google sheet
- Make the first column "timestamp"
- Click on "Tools" > "Script Editor..."
- Name your project something memorable
- Replace contents of code.gs with this file
- Change the name of your tab in the sheet
- Update the variable "SHEET_NAME" in the code from step 5
- Add columns you want as fields in your form, the fields should match your HTML exactly
- Add any required fields with messages to the "fields" object
- Edit the "testData" to match your sheet fields
- Click on Run > Run Function > "test_post"
- Confirm this data is inserted into your sheet
- If everything works, Click on Publish and select "Deploy as web app"
- Select new and type a version name (e.g 0.1.0) (or update existing)
- In "Execute the app as" select yourself
- In "Who has access to the app" Select "Anyone, even anonymous"
- Click Deploy or Update
- Click "Review Permissions", to Authorize application
- When you see a warning, Click "Advanced" and "Go to PROJECT_NAME"
- Review list of permissions required, and click "Allow"
- Copy and paste URL (note: if you're logged into multiple Google accounts you'll have to manually remove "/u/0" or similar from the URL to avoid errors)
- Setup your HTML form to post to the URL from step 21
yarn add form-google-sheets
import { Form } from 'form-google-sheets'
const endpoint = 'https://script.google.com/macros/s/AKfycbyEBGqfIUmxrLKMp_LlAlH8C_VO9vfRvtvwgjAS9lEi8Vu8xho/exec'
const form = new Form(endpoint).then((event) => {
console.log('SUCCESS')
console.log(event)
}).catch((event) => {
console.log('ERROR')
console.log(event)
})
var Form = require('form-google-sheets').Form
var endpoint = 'https://script.google.com/macros/s/AKfycbyEBGqfIUmxrLKMp_LlAlH8C_VO9vfRvtvwgjAS9lEi8Vu8xho/exec'
var form = new Form(endpoint).then((event) => {
console.log('SUCCESS')
console.log(event)
}).catch((event) => {
console.log('ERROR')
console.log(event)
})
<script src="form-google-sheets.js"></script>
var endpoint = 'https://script.google.com/macros/s/AKfycbyEBGqfIUmxrLKMp_LlAlH8C_VO9vfRvtvwgjAS9lEi8Vu8xho/exec'
var form = new FormGoogleSheets.Form(endpoint).then(function(event) {
console.log('SUCCESS')
console.log(event)
}).catch(function(event) {
console.log('ERROR')
console.log(event)
})
There is a test function setup that you can change to include your own fields and make sure your form is setup correctly.
- Change the testData in test_post()
- Move to Run in the top menu
- Click function test_post()
# Run unit test
yarn test
# Create new versioned release
yarn run release
You can see examples of use in javascript under /docs.
You can see the (view only) sheet that this posts to here: https://docs.google.com/spreadsheets/d/1SRRfFOpIJyW6tZB1TP3wJf01CFISviIMFEJDgwoqq5w/edit?usp=sharing
https://github.com/dwyl/html-form-send-email-via-google-script-without-server
All contributors are welcome, please follow CONTRIBUTING.md