javascript - HTML 表单数据到 Google 电子表格

标签 javascript html forms google-sheets google-sheets-api

我查看了之前发布的各种有关使用 JavaScript 将 HTML 表单数据提交到 Google 电子表格数据的条目。然而,自之前的帖子以来,Google 电子表格已经发生了很大的变化,以及 <input> 的方式entries work ,所以我不确定如何让我的表单写入 Google 电子表格。我基本上遵循了此URL中的解决方案。我的代码如下。有人对如何解决有建议吗?问题在于缺少输入字段。我的表单只有 id=firstname 和 id=lastname,所以一开始就很简单。预先感谢您的查找。

<html>
<head>
<script>
    $('#emailForm').one('submit',function(){
    var inputField = encodeURIComponent($('#emailForm').val());
    var baseURL = 'https://docs.google.com/a/google.com/forms/d/1RZYnGjYAMjl6LMXLdsWZgb9S3NqXZSO000tD2eObhLc/formResponse';
    var submitRef = '&submit=Submit';
    var submitURL = (baseURL + emailAddress + submitRef);
    $(this)[0].action=submitURL;
    $('#email').addClass('active').val('Thank You!');
setTimeout(function(){
  $('#form-container').hide();
  $('#update-form').animate({'width': '0px'},300,function(){
        $('#get-updates-link').hide();
          $('#email-submit').addClass('active').val('Thank You!');
      });
    },1000);
</script>
</head>
<body>

<form id="emailForm" action="https://docs.google.com/a/google.com/forms/d/1RZYnGjYAMjl6LMXLdsWZgb9S3NqXZSO000tD2eObhLc/formResponse">

  <input id="firstname" type="text" placeholder="enter firstname" name="firstname">
  <input id="lastname" type="text" placeholder="enter lastname" name="lastname">
  <button id="email-submit" type="submit">Submit</button>
</form>


</body>
</html>

最佳答案

你这样做的方式很有趣,但是还有更好的方法。为了使您当前的策略发挥作用,您需要创建一个与您的数据匹配的 Google 表单。你不需要这样做。最好创建一个独立的应用程序脚本 Web 应用程序,其中包含 doPost(e) 函数。该 doPost(e) 函数可以捕获 HTTP 请求负载,并在调用 Apps 脚本 Web 应用程序 URL 时运行 doPost(e) 函数。 e 参数将从 POST 请求捕获有效负载数据。

您可以查看类似这样的 stackoverflow 问题:

Call a custom Apps Script function from external url

关于javascript - HTML 表单数据到 Google 电子表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34601748/

相关文章:

javascript - 使用带有验证的 php 在弹出窗口中预览表单详细信息

javascript - 如何将数字存储在数组中?

javascript - 如何将 Bootstrap Burger 菜单功能添加到常规 Bootstrap 菜单?

javascript - 打开页面加载javascript的线索提示

c++ - 识别应用程序的架构

c# - 当 this.Close() 执行所有表单时关闭?

javascript - 运行 selenium 测试时处理 javaScript 警报?

jquery - 我第一次点击 jquery 移动页面会添加溢出 :hidden on body tag

html - 在表单中并排放置 html 按钮时出现问题

javascript - 导入 .less 变量以在 React 样式组件中使用