Skip to content

Instantly share code, notes, and snippets.

@jackhftang
Created March 10, 2017 10:03
Show Gist options
  • Save jackhftang/970853bee25b6245bbda80528dcc2e11 to your computer and use it in GitHub Desktop.
Save jackhftang/970853bee25b6245bbda80528dcc2e11 to your computer and use it in GitHub Desktop.
An easy google sheet for landing page
var SHEET_NAME = "Sheet1";
function doGet(e) {
return handleResponse(e);
}
function doPost(e) {
return handleResponse(e);
}
function handleResponse(e) {
var lock = LockService.getPublicLock();
lock.waitLock(30 * 1000);
try {
var doc = SpreadsheetApp.getActive();
var sheet = doc.getSheetByName(SHEET_NAME);
var name = e.parameter.name;
var email = e.parameter.email;
if (!name) throw new Error('no name');
if (!email) throw new Error('no email');
sheet.appendRow([new Date(), name, email]);
return ContentService
.createTextOutput(JSON.stringify({"result": "success"}))
.setMimeType(ContentService.MimeType.JSON);
} catch (e) {
return ContentService
.createTextOutput(JSON.stringify({"result": "error", "error": e}))
.setMimeType(ContentService.MimeType.JSON);
} finally {
lock.releaseLock();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment