我查看了有关此主题的类似问题,但仍然无法完全了解如何获取在HTML创建的表单中输入的数据。
这就是我想要做的事情:
我遵循此tutorial并且能够让它发挥作用。问题是UI(电子表格形式)不是我想要的。我想要一个HTML格式的表单,但无法正确地从中提取数据。
以下是我使用电子表格表单创建的示例脚本。
var docTemplate = "1234567890"; // Template ID
var docName = "FinalDocument"; // Name of the document to be created
// When form gets submitted
function onFormSubmit(e) {
// Get information from form and set as variables
var email_address = e.values[1];
var full_name = e.values[2];
// Get document template, copy it and save the new document's id
var copyId = DocsList.getFileById(docTemplate)
.makeCopy(docName+' for '+full_name)
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);
// Get the document's body section
var copyBody = copyDoc.getActiveSection();
// Replace place holder keys,in our google doc template
copyBody.replaceText('keyEmailAddress', email_address);
copyBody.replaceText('keyFullName', full_name);
// Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF by using the getAs blob conversion
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
var subject = "Final Document";
var body = "Here is the form for " + full_name + "";
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf});
// Delete temporary file
DocsList.getFileById(copyId).setTrashed(true);
}
这是使用我刚创建的HTML的新表单。
<html>
<form id="myForm">
<input name="fullName" id="_fullName">
<input name="emailAddress" id="emailAddress">
<input type="button" id="submit" value="submit" onclick = "sendData()">
</form>
<script>
function sendData() {
google.script.run.processForm(document.getElementById("myForm"));
}
</script>
</html>
有人可以帮助我开始使用电子表格表单转换为HTML表单吗?如何从HTML表单中提取数据?
答案 0 :(得分:0)
您可能想参考我之前在Accessing object is Google App Script
提出的问题所以对于你的情况应该是:
// Get information from form and set as variables
var email_address = e.emailAddress;
var full_name = e.fullName;
至于你的HTML代码
<html>
<form id="myForm">
<input name="fullName" id="_fullName">
<input name="emailAddress" id="emailAddress">
<input type="button" id="submit" value="submit" onclick = "google.script.run.processForm(this.parentNode)">
</form>
</html>
请试一试,我没时间测试代码。很抱歉。