【发布时间】:2012-08-08 05:57:03
【问题描述】:
我在使用 HtmlService 创建的 html 表单中调用服务器端 GAS 函数时遇到问题。 HtmlService 文档说以下应该可以工作:
<form id='myForm'>
<input name='myFile' type='file'>
<input name='aField'>
<input type='button' onclick='google.script.run.processForm(this.parentNode)'>
</form>
我正在使用类似的东西:
<form id='approveForm'>
<b>Enter Notes about this Approval : </b>
<br /><br />
<textarea id = 'approvalNotes' rows='10' cols='135'>Enter notes on this approval for future reference...</textarea>
<br /><br />
<b>Request Approved?</b>
<br /><br />
<input name = "decision" type="radio" id = 'rApproval' value='Yes'/>Yes<br />
<input name = "decision" type="radio" id = 'rApproval' value ='No'/>No<br />
<input name = "decision" type= "radio" id = 'rApproval' value='Pending'/>Pending<br />
<br /><br />
<b>Set the Group/List Type : </b>
<br /><br />
<input name = "gltype" type="radio" id = 'glType' value='Group'/>Group<br />
<input name = "gltype" type="radio" id = 'glType' value='List'/>List<br />
<input name = "gltype" type="radio" id = 'glType' value='?'/>?<br />
<br />
<input type='button' value='submit' onclick='google.script.run.processForm(this.parentNode)'>
</form>
虽然我已经做了几乎与文档所说的用于表单提交相同的事情,但我的服务器端函数并没有被调用。有人可以告诉我可能做错了什么以及如何解决这个问题。
【问题讨论】:
-
我刚刚测试了你的代码,它运行良好。只有您可能想给 textarea 输入一个名称,以便您可以解析它。尝试添加 Logger.log(JSON.stringify(form));在您的 processForm 函数中验证表单是否已传递并且该函数是否真正被调用。