1
votes

I have some form on my pure JS/HTML/CSS site (without server side). And have Google account. My purpose is send filled form from web client direct to Google Spreadsheet. Is it possible?

1

1 Answers

1
votes

Yes, this is possible. I would do it by creating an Apps Script and deploying it as a web app. Here is a sample script: fill in the Id of the spreadsheet and the name of one of its sheets.

function doPost(event) {
  var params = event.parameter;
  var sheet = SpreadsheetApp.openById('..Id..').getSheetByName('..Name..');
  if (params.data !== undefined) { 
    sheet.getRange(1, 1).setValue(params.data);
    return ContentService.createTextOutput("Success");
  }
  else {
    return ContentService.createTextOutput("Oops");
  }  
}

Publish the script as a web app, allowing access to everyone (unless you want to deal with authentification). This will give you a URL such as https://script.google.com/macros/s/..../exec

On the client side, you send POST request to that URL. The script expects data to be in parameter "data".

var url = 'https://script.google.com/macros/s/..../exec';
$.post(url, {data: 'hello world'});

(I'm using jQuery here just to have a shorter example; you can send a POST request in plain JavaScript.)

The cell A1 of the sheet you chose will have "hello world".