HtmlService doPost使用Google文档格式 [英] HtmlService doPost With Google Docs Form

查看:74
本文介绍了HtmlService doPost使用Google文档格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

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

 函数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文件中的表单动作代码行如下所示。 p>

 < form action =<?=https://docs.google.com/spreadsheet/formResponse?formkey=$ mungedformkey?>方法= POST > 


解决方案

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


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">

解决方案

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.

这篇关于HtmlService doPost使用Google文档格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆