【问题标题】:HtmlService doPost With Google Docs Form带有 Google Docs 表单的 HtmlService doPost
【发布时间】:2012-10-16 03:28:27
【问题描述】:

我创建了一个谷歌文档表单并制作了一个谷歌脚本小工具,将数据发布到表单的电子表格后端,然后返回一个自定义的html5 确认页面。

我在脚本代码中使用了HTMLService、doPost(e) 和doGet(e),还用我的小工具创建了2 个html 文件(表单和确认html 文件)。

将数据写入正确电子表格的小工具;但是,它没有返回我使用小工具创建的正确确认 html 文件。它返回确认页面,该页面是谷歌文档表单的一部分。下面是我的代码的doPost 部分的片段。有没有人知道如何让它返回我创建的自定义确认 html 文件而不是 Google 文档?

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();  
}

我的 form.html 文件中的表单操作代码行如下。

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

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    当您发布到某个 URL 时,该 URL 将决定接下来会发生什么 - 您的 doPost 永远不会被调用。作为替代方案,尝试发布到脚本(使用 doPost 或更好地使用 google.script.run post 语法)并使用 UrlFetchApp 将数据传递到表单;然后你就可以控制表单响应了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-30
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多