| A | B | C | ... | |
|---|---|---|---|---|
| 1 | timestamp | name | ... | |
To learn how to add additional input fields, checkout section 7 below.
Tools > Script Editor… which should open a new tab.Submit Form to Google Sheets Make sure to wait for it to actually save and update the title before editing the script .File > Save
var sheetName = 'Sheet1'
var scriptProp = PropertiesService.getScriptProperties()
function intialSetup () {
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet()
scriptProp.setProperty('key', activeSpreadsheet.getId())
}
function doPost (e) {
var lock = LockService.getScriptLock()
lock.tryLock(10000)
try {
var doc = SpreadsheetApp.openById(scriptProp.getProperty('key'))
var sheet = doc.getSheetByName(sheetName)
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0]
var nextRow = sheet.getLastRow() + 1
var newRow = headers.map(function(header) {
return header === 'timestamp' ? new Date() : e.parameter[header]
})
sheet.getRange(nextRow, 1, 1, newRow.length).setValues([newRow])
return ContentService
.createTextOutput(JSON.stringify({ 'result': 'success', 'row': nextRow }))
.setMimeType(ContentService.MimeType.JSON)
}
catch (e) {
return ContentService
.createTextOutput(JSON.stringify({ 'result': 'error', 'error': e }))
.setMimeType(ContentService.MimeType.JSON)
}
finally {
lock.releaseLock()
}
}If you want to better understand what this script is doing, checkout the
form-script-commented.jsfile in the repo for a detailed explanation.
Run > Run Function > initialSetup to run this function.Authorization Required dialog, click on Review Permissions .Hi {Your Name} , Submit Form to Google Sheets wants to ...AllowEdit > Current project’s triggers. No triggers set up. Click here to add one now. doPostFrom spreadsheet and On form submitSavePublish > Deploy as web app….Project Version to New and put initial version in the input field below.Execute the app as: set to Me([email protected]).Who has access to the app: select Anyone, even anonymous.Deploy.Current web app URL from the dialog.OK.IMPORTANT! If you have a custom domain with Gmail, you might need to click
OK, refresh the page, and then go toPublish > Deploy as web app…again to get the proper web app URL. It should look something likehttps://script.google.com/a/yourdomain.com/macros/s/XXXX….
Open the file named submit-form.js On line 1 paste your SCRIPT URL inside: ' '
You are done !
To capture additional data, you'll just need to create new columns with titles matching exactly the name values from your form inputs. For example, if you want to add first and last name inputs, you'd give them name values like so:
<form name="submit-to-google-sheet">
<input name="email" type="email" placeholder="Email" required>
<input name="firstName" type="text" placeholder="First Name">
<input name="lastName" type="text" placeholder="Last Name">
<button type="submit">Send</button>
Then create new headers with the exact, case-sensitive name values:
| A | B | C | D | ... | |
|---|---|---|---|---|---|
| 1 | timestamp | firstName | lastName | ... | |
Get Api Key copy that keyBootstrap-Image-Uploader.js
" " double inverted colons Name fields in form so you need to insert it manually and make sure that the name matches exactly as it is url in sheets to get the URL of image in sheets For more info in
nametag go to section 7 in first qustion