【发布时间】:2018-04-08 08:26:07
【问题描述】:
我正在尝试在容器绑定的侧边栏中提交 html 表单的输入结果,并将它们复制到谷歌表格。我查看了该站点以及其他站点 (https://www.packtpub.com/mapt/book/web_development/9781785882517/4/ch04lvl1sec48/submitting-form-using-google-script-api-method) 中的一些代码示例,但也许因为我是 html/javascript/gas 的新手,发现它们令人困惑且难以理解,因此我编写的代码不是t工作,我不知道为什么。
简而言之,我想将在“formcommenttext”输入文本框中输入的值传递给我的 Google Apps 脚本函数“postCommentToSheet”,我希望我可以在其中获取用户输入的值并且(最终) 将其写入谷歌表格。
有什么建议吗?
这是我的 html 代码:
<!-- input control to add comment -->
<form id="addCommentForm">
<fieldset>
<legend>Add your comment:</legend>
<br>
<input type="text" name="formcommenttext" value=""><br>
<input type="submit" value="Add" onclick="google.script.run.postCommentToSheet(this.parentNode);">
<input type="reset" value="Cancel">
</fieldset>
</form>
我还将以下代码 sn-p 包含到我的 html 表单的脚本部分中(如其他地方所建议的那样),尽管我不清楚它的作用以及如何对其进行编辑以满足我的需要。
function postData(form){
google.script.run
.withSuccessHandler(callback)
.withFailureHandler(callback)
.postFormDataToSheet(form);
}
这是我的 .gs 代码:
function postCommentToSheet(formObject) {
//read formcommenttext from add comment form:
//https://www.packtpub.com/mapt/book/web_development/9781785882517/4/ch04lvl1sec48/submitting-form-using-google-script-api-method
var result = GLOBAL_UI.alert(formObject.formcommenttext.value)
//get comments data sheet
var ss = GLOBAL_DataFile.getSheetByName("Comments");
ss.appendRow([formObject.formcommenttext]);
}
【问题讨论】: