HtmlService doPost With Google Docs Form

2019-05-14 01:47发布

I created a google docs form and made a google 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 docs 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">

1条回答
神经病院院长
2楼-- · 2019-05-14 02:20

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.

查看更多
登录 后发表回答