我正在通过https://developers.google.com/apps-script/guides/html/communication尝试提交一个包含从Google工作表加载的信息的表单。在客户端我有(严重依赖于文章中的表单示例):
int between (tree t, int a, int b) {
if (t== NULL)
return 0;
if ((t->data >a ) && ( t->data <b))
return 1 + between(t->left,a,b) + between(t->right,a,b);
else if(t->data<a)
return between(t->right,a,b);
else if(t->data>b)
return between(t->left,a,b);
}
在服务器端(code.gs)我有:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
// Prevent forms from submitting.
function preventFormSubmit() {
var forms = document.querySelectorAll('form');
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener('submit', function(event) {
event.preventDefault();
});
}
}
// window.addEventListener('load', preventFormSubmit);
function handleFormSubmit(formObject) {
google.script.run.withSuccessHandler(updateUrl).processForm(formObject);
}
// function updateUrl(url) {
// var div = document.getElementById('output');
// div.innerHTML = '<a href="' + url + '">Got it!</a>';
// }
</script>
</head>
<body>
<form id="myForm" onsubmit="handleFormSubmit(this)">
<div>
<select id="optionList" name="email">
<option>Loading...</option>
</select>
</div>
<br>
<div>
<textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>
</div>
<input type="submit" value="Submit" />
</form>
我可以看到提交正常,因为我在日志中看到“在这里”。如何从processForm函数中访问表单字段?
答案 0 :(得分:1)
这个块对我来说没有意义
var formBlob = formObject.myFile;
您的表单不包含其姓名&#39;属性设置为&#39; myFile&#39;。点击“提交”后,&#39; formObject&#39;变量将是:
{
email: "Loading...", //from <select id="optionList" name="email">
message: "The cat was playing in the garden." //from <textarea name="message">
}