Install:
brew install gnupg # on Mac OS
apt-get install gnupg # on Ubuntu/Debian
...
function callWithScriptLock(callback, arg1, arg2) { | |
var lock = LockService.getScriptLock(); | |
lock.waitLock(30000); | |
try { | |
return callback(arg1, arg2); | |
} finally { | |
lock.releaseLock(); | |
} | |
} |
<script data-cfasync="false" type="text/javascript"> | |
jQuery( document ).ready(function( $ ) { | |
var request; | |
$("#my_form").submit(function(event){ | |
if (request) { request.abort(); } | |
$('#result').text('Sending data...'); | |
request = $.ajax({ | |
url: "https://script.google.com/macros/s/AKfycbz4aFabJ80gajXFBcXlFLpR6n9ad9GHs4UcT6ux9w7RAYcI_9w/exec", |
function doPost(e) { | |
try { | |
var newRow = createNewRowAndWriteToSheet(e.parameter); | |
return JsonFormattedSuccess(newRow.toString()); | |
} catch(error) { | |
return JsonFormattedError(error) | |
} | |
} | |
function JsonFormattedSuccess(success_message) { |
var SCRIPT_PROPERTIES = PropertiesService.getScriptProperties(); | |
function registerSpreadsheetWithScript() { | |
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
SCRIPT_PROPERTIES.setProperty("spreadsheetId", spreadsheet.getId()); | |
SCRIPT_PROPERTIES.setProperty("sheetName", sheet.getName()); | |
} |
function registerSheetWithScript() { | |
... | |
SpreadsheetApp.getUi().alert('This sheet will now receive data from forms!'); | |
} | |
function onOpen() { | |
SpreadsheetApp.getUi().createMenu('FormBackend') | |
.addItem('Register sheet', 'registerSheetWithScript') | |
.addToUi(); | |
} |
<form id="my_form"> | |
<p> | |
<label>Name:</label> | |
<input name="name" type="text" value=""/> | |
</p> | |
<p> | |
<label>Email:</label> | |
<input name="email" type="text" value=""/> | |
</p> | |
<p> |
... | |
$.ajax({ | |
url: "https://script.google.com/macros/s/AKfycbz4aFabJ80gajXFBcXlFLpR6n9ad9GHs4UcT6ux9w7RAYcI_9w/exec", | |
// this was 'url: "././mail/contact_me.php"' | |
type: "POST", | |
data: { | |
name: name, | |
phone: phone, | |
email: email, | |
message: message |
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, |
function createNewRowAndWriteToSheet(parameters) { | |
var sheet = getSheet(); | |
var headers = getHeaders(sheet); | |
var newRow = createRow(headers, parameters); | |
callWithScriptLock(writeRowToSheet, sheet, newRow); | |
return newRow; | |
} | |
function getSheet() { | |
var spreadsheet = SpreadsheetApp.openById(SCRIPT_PROPERTIES.getProperty("spreadsheetId")); |