0

I created a form in Google Script and one of the fields is a Checkbox, the name of the field would be field1 []

and to save the answers in a sheet, I am using AppendRow, but when I insert the name of the field that has [], I get an error, and if I remove them the selections are not saved correctly.

This is my code.gs

function doGet(request) {
  return HtmlService.createTemplateFromFile('Index')
      .evaluate();
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}

/* @Process Form */
function processForm(formObject) {
  var url = "https://docs.google.com/spreadsheets/d/12CUQaajvhcQjcskDgA7YHc6EWdK67wq9LqBiauBoi4/edit#gid=0";
  var ss = SpreadsheetApp.openByUrl(url);
  var ws = ss.getSheetByName("Data");

  ws.appendRow([
 
  formObject.field1]);
}
1
  • Welcome to Web Applications. There are missing details, more specifically the Index.html file (add a minimal, complete and verifiable version). – Rubén Apr 19 at 19:04
1

ws.appendRow([formObject.field1]);

That looks fine, provided that the HTML form includes an input with that exact name, as in <input name="field1">.

when I insert the name of the field that has []

If you really have a form input field whose name attribute is something like field1[], you should probably choose a different name. If you cannot change the name attribute for some reason, try this in your server-side code:

ws.appendRow([formObject.['field1[]']]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.