Веб-приложение Google Sheets регистрирует несколько вариантов - PullRequest
0 голосов
/ 14 марта 2019

Я взял пример из книги, чтобы адаптировать его.Дело в том, что в исходном коде есть радио-проверка (чтобы включить только одну опцию), и я хотел бы иметь их в качестве флажков (чтобы зарегистрировать несколько вариантов).Я внес изменения в HTML-код, и он выглядит хорошо, но электронная таблица по-прежнему регистрирует один из вариантов вместо всех.Не могли бы вы дать мне знать, что мне не хватает?

Вот HTML-код проекта

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <form method="post" action="<?= pubUrl ?>">
 <h4>Where will you go for vacation?</h4>
 <? for (var i in places) { ?>
 <input type="checkbox" name="places"
 value="<?= places[i] ?>" /><?= places[i] ?><br />
 <? } ?>
 <br />
 <input type="submit" value="SUBMIT" />

 </form>

  </body>
</html>

А вот и ГАЗ (Google Script)

function doGet() {
 // Replace with your spreadsheet's ID.
 var ss = SpreadsheetApp.openById("1hpYbBbpVfxsciVCpZGBcqHPeBo2Wuj7U1Y9CaxsI9go");
 var SheetPlaces = ss.getSheetByName("Places");

 var data = SheetPlaces.getDataRange().getValues();

 // Remove header row.
 data.shift();

 var places = [];

 // Populate the places array with the first column's data.
 data.forEach(function(row){
 places.push(row[0]);
 });

 var template = HtmlService.createTemplateFromFile("form.html");
  
 //Assign the published URL to the template object in the doGet 
template.pubUrl =  "https://script.google.com/macros/s/AKfycbx90heH12wfP4-kVZCOkEpI7Bi5wqpDAf-ndLrf3bPPYSwwEp5Q/exec";
  //o
  //template.pubUrl = ScriptApp.getService().getUrl();
 // Assign the places array to the template object.
 template.places = places;
 var html = template.evaluate();
 return HtmlService.createHtmlOutput(html);
}

function doPost(e){  
  // Replace with your spreadsheet's ID.  
  var ss = SpreadsheetApp.openById("1hpYbBbpVfxsciVCpZGBcqHPeBo2Wuj7U1Y9CaxsI9go");
  var SheetResponses = ss.getSheetByName("Responses");   
  // Create a 'Responses' sheet if it does not exist.  
  if(!SheetResponses){     SheetResponses = ss.insertSheet("Responses");
   };    SheetResponses.appendRow([e.parameter.places]);    return ContentService.createTextOutput(     "Your response submitted successfully. Thank you!"  );
}


function createForm() {

 var ThisSpreadsheet = SpreadsheetApp.getActive();
 var SheetPlaces = ThisSpreadsheet.getSheetByName("Places");
  
  
 // Load 'Places' sheet data as a 2-dimensional array.
 var data = SheetPlaces.getDataRange().getValues();

 // remove the header row
 data.shift();

 var places = [];

 // Populate the places array with the first column's data
 data.forEach(function(row){
 places.push(row[0]);
 });

 // Create a new form
 var form = FormApp.create("Vacation Form");

 form.addMultipleChoiceItem()
 .setTitle('Where will you go for a vacation?')
 .setChoiceValues(places)
 .showOtherOption(true)

}

Также вот URL веб-приложения https://script.google.com/macros/s/AKfycbx90heH12wfP4-kVZCOkEpI7Bi5wqpDAf-ndLrf3bPPYSwwEp5Q/exec

Спасибо за вашу помощь!

...