表单不会发布,因为它onsubmit='return false'
在 caja sanatizing 后获取了属性。如果您删除它,那么它会按预期工作:
您可以使用 jQuery 将其删除,例如:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
var form = $('#form');
form.removeAttr('onsubmit');
</script>
测试和工作。完整代码如下:
代码.gs
function doGet(e) {
var template = HtmlService.createTemplateFromFile('Index.html');
template.action = ScriptApp.getService().getUrl();
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
function doPost(e) {
Logger.log(e);
var template = HtmlService.createTemplateFromFile('thanks.html');
template.phone = e.parameter.phone;
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
索引.html
<form id='form' action="<?= action ?>" method="POST">
<label>Phone: <input type="text" name="phone"></label><br>
<label><input type="submit"></label>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
var form = $('#form');
form.removeAttr('onsubmit');
</script>
谢谢.html
<div>
Thanks,
You entered <?= phone ?>!
</div>