Search code examples
javascriptformsgoogle-apps-scriptweb-applicationstemplate-engine

HtmlService doPost With Google Form


I created a Google Form and made a Google Apps Script gadget to post the data to the spreadsheet backend of the form and then return a custom html5 confirmation page.

I used HTMLService, doPost(e) and doGet(e) in my script code, and also created 2 html files with my gadget (the form and the confirmation html files).

The gadget it writing the data to the correct spreadsheet; however, it's not returning the correct confirmation html file I created with my gadget. It's returning the confirmation page which is part of the google docs form. A snip of the doPost portion of my code is below. Does anyone have any ideas how to make it return the custom confirm html file I created instead of the Google Forms one?

function doPost(e) {
  var template = HtmlService.createTemplateFromFile('confirm.html');
  template.entry_0 = e.entry_0;
  template.entry_1 = e.entry_1;
  template.entry_2 = e.entry_2;
  template.entry_3 = e.entry_3;
  template.screenshot = e.parameter.screenshot;
 return template.evaluate();  
}

The form action code line in my form.html file is below.

<form action="<?= "https://docs.google.com/spreadsheet/formResponse?formkey=$mungedformkey" ?>" method="post">

Solution

  • When you post to a URL, that URL is what decides what happens next - your doPost is never getting invoked. As an alternative, try posting to the script (either using doPost or better using the google.script.run post syntax) and using UrlFetchApp to pass the data to the form; then you will get to control the form response.