gpt4 book ai didi

javascript - 访问 HTML 服务表单对象

转载 作者:行者123 更新时间:2023-11-30 21:11:00 25 4
gpt4 key购买 nike

enter image description here

我正在处理 https://developers.google.com/apps-script/guides/html/communication试图提交一个表格,其中包含从谷歌工作表加载的信息。在客户端,我有(主要基于文章中的表单示例):

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

在服务器端 (code.gs) 我有:

function processForm(formObject) {

Logger.log('in here');
var formBlob = formObject.myFile;
var driveFile = DriveApp.createFile(formBlob);

return driveFile.getUrl();
}

我可以看到提交工作正常,因为我在日志中看到“在这里”。如何从 processForm 函数中访问表单字段?

最佳答案

这个 block 对我来说没有意义

  var formBlob = formObject.myFile;

您的表单不包含“名称”属性设置为“myFile”的输入。单击“提交”后,“formObject”变量将为:

{
email: "Loading...", //from <select id="optionList" name="email">
message: "The cat was playing in the garden." //from <textarea name="message">

}

关于javascript - 访问 HTML 服务表单对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46141289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com