Will Scott

White Label Google Forms

Google Forms are a reasonable option for conducting quick surveys without having to manage your own server. Sometimes, though, you want a bit more control over the user experience than what is provided by the template.

Google App Script lets you do this, the following script dumps provided variables into a spreadsheet, just like a Form would do:

function doGet(request) {
  var result = {
    success: true
  };

  if (request && request.parameter && request.parameter.[name]) {
    var dataSS = SpreadsheetApp.openById("[spreadsheet id]");
    var sheet = dataSS.getActiveSheet();
    sheet.appendRow([
      Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'"),
      request.parameter.[name]
    ]);
  } else {
    result.success = false;
  }
  
  return ContentService.createTextOutput(
      'callback(' + JSON.stringify(result) + ')')
      .setMimeType(ContentService.MimeType.JSON);
}
Exit mobile version