Google Apps 脚本 HTML 表单

判断

我有一个带有电子邮件发送的简单 html 表单

这是 html 文件:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
      function submitForm() {
        var name = document.getElementById('name').value;
        var email = document.getElementById('email').value;
        var comment = document.getElementById('comment').value;
        
        /**
         * First run submitData(name, email, comment) function of Code.gs
         * Then, run showMessage(value) function of this html file
         */
        google.script.run
              .withSuccessHandler(showMessage) // execute showMessage(value) function on success
              .submitData(name, email, comment); // call submitData(name, email, comment) function present in Code.gs file
      }
      
      function showMessage(value) {
        document.getElementById('message').innerHTML = value;
        document.getElementById('name').value = '';
        document.getElementById('email').value = '';
        document.getElementById('comment').value = '';
      }
    </script>
  </head>
  <body>
    <h2>Feedback Form</h2>
    <div id="message" style="color:green"></div>
    <p><input id="name" type="text" placeholder="Your Name"><p>
    <p><input id="email" type="email" placeholder="Your Email"></p>
    <p><textarea id="comment" rows="10" cols="40"></textarea></p>
    <p><button onclick="submitForm(); return false;">Submit</button></p>    
  </body>
</html>

这是 gs 文件:

function doGet(e) {
  return HtmlService
    .createHtmlOutputFromFile('index.html')
    .setTitle("Simple HTML Form Example");
}
 
function submitData(name, email, comment) {
  var subject = 'New Feedback';
  var body = 'Name: ' + name + '<br> Email: ' + email + '<br> Comment: ' + comment;
  var to = '[email protected]'; // EMAIL ADDRESS WHERE THE FEEDBACK EMAIL IS SENT
  MailApp.sendEmail({
      to: to,
      subject: subject,
      htmlBody: body
    }); 
  
  return 'Feedback Sent!';
}

我正在寻找一个公式来查看编辑的字段名称、电子邮件,而不是文本“反馈已发送!”

先谢谢您的帮助!

库柏

HTML 电子邮件表单

html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
      function submitForm(form) {
        google.script.run
        .withSuccessHandler(function(value){
          document.getElementById('message').innerHTML = value;
          document.getElementById('name').value = '';
          document.getElementById('email').value = '';
          document.getElementById('comment').value = '';
        }) 
        .submitData(form);
      }
    </script>
  </head>
  <body>
    <h2>Feedback Form</h2>
    <div id="message" style="color:green"></div>
    <form>
    <br /><input id="name" type="text" name="name" placeholder="Your Name">
    <br /><input id="email" type="email" name="email" placeholder="Your Email">
    <br /><textarea id="comment" rows="10" cols="40" name="comment"></textarea>
    <br /><input type="button" value="Submit" onclick="submitForm(this.parentNode);" />  
  </form>  
  </body>
</html>

谷歌脚本:

function submitData(form) {
  var subject='New Feedback';
  var body=Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
  var to = '[email protected]'; 
  MailApp.sendEmail({to: to,subject: subject,htmlBody: body}); 
  //Logger.log('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
  return Utilities.formatString('name: %s <br />Email: %s<br />Comment: %s', form.name,form.email,form.comment);
}
//It works as a dialog
function showTheDialog() {
  var userInterface=HtmlService.createHtmlOutputFromFile('aq7');
  SpreadsheetApp.getUi().showModelessDialog(userInterface, "Emails")
}

在此处输入图片说明

在此处输入图片说明

我实际上并没有用 mailapp 线测试它。我刚刚使用了 Logger,看到它返回了反馈消息。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Google Apps脚本HTML表单无法提交

带有HTML表单的Google Apps脚本

google apps脚本:html-表单提交,获取输入值

使用Google Apps脚本解析表单提交

复制带有表单的Google Apps脚本

使用Google Apps脚本触发HTML表单提交上的邮件发送

HTML表单输入字段为空时,Google Apps脚本中出现错误

将Google Apps脚本数组应用于HTML表单自动完成数据列表

Google Apps脚本HTML服务键事件

HTML href作为Google Apps脚本变量

错误提交表单Google Apps脚本错误值

Google Apps 脚本:在创建表单期间设置默认答案

将触发Google Apps脚本最新表单响应-

Google Apps脚本-动态添加删除UiApp表单元素

如何使用Google Apps脚本处理表单?

由特定表单提交触发的Google Apps脚本OnSubmit函数

如何使用Google Apps脚本和JavaScript在HTML表单字段中自动显示用户电子邮件

在 Google Apps 脚本中,如何通过重新加载 doPost() 返回的 HTML 来防止多次提交表单数据?

在Google Apps脚本中提交HTML表单时,如何与输入一起发送地理位置信息

在 Google Apps 脚本中,如何通过重新加载 doPost() 返回的 HTML 来防止多次提交表单数据?

使用Google Apps脚本将Google表单问题添加到表单的特定部分

Google Apps脚本和Google表单:这是“添加标题和描述”的类表单方法

Google Apps脚本要求

调用Google Apps脚本

Google Apps脚本-MailApp

Google Apps 脚本 indexOf

Google Apps脚本:onEdit

如何使用Google Apps脚本检索用户在Google表单中的“其他”字段中输入的值?

如何使用Google Apps脚本在Google表单中获取URL参数?