【问题标题】:Bad HTML contact form redirecting to script.googleusercontent.com after submission提交后重定向到 script.googleusercontent.com 的错误 HTML 联系表单
【发布时间】:2018-11-10 20:06:09
【问题描述】:

以下联系表格http://wearedappr.com/contact.html 在提交后将所有信息发送到谷歌电子表格。但是,它也会将用户重定向到https://script.googleusercontent.com(见下图)

我正在尝试显示确认消息而不是重定向。诸如“感谢您与我们联系!我们会尽快回复您!”之类的内容。一旦我们提交它,它就会出现在联系表单页面上。

有人可以帮忙吗?

这里是 form-submission-handler.js: http://wearedappr.com/form-submission-handler.js

【问题讨论】:

  • 你能分享你的HTML代码吗?
  • 我怀疑您将表单直接提交给 Google。实现您想要的最佳方法是使用 Ajax 提交表单,他们解析 json 响应并在成功时向您显示确认消息
  • 这里是HTML代码查看源:wearedappr.com/contact.html
  • @ChukaOkoye,我一直在尝试按照您的描述进行操作,但没有任何成功。你知道我在哪里可以找到这样的例子吗?谢谢
  • 我会尽快发布答案。给我一点时间来打开我的电脑

标签: html google-apps-script contact-form


【解决方案1】:

试试这些。

1,将您的开始表单标签更改为:

<form class="gform pure-form pure-form-stacked" id="google_form_submit">

2,在结束正文标记之前添加以下代码

<script type="text/javascript">
  $('#google_form_submit').submit(function(e){
      e.preventDefault();
      var formData = $('#google_form_submit').serialize();
      $.ajax({
            type        : 'POST', 
            url         : 'https://script.google.com/macros/s/AKfycbzBvgWZZUgFbxCAlhPG4429wth61Rm7kymPaui3d5328UHHOiA/exec',
            data        : formData, 
            dataType    : 'json',
            encode      : true
       }).done(function(data) {
            if(data.result == 'success') {
              // Form submission was successful and accepted by google. 
              // You can show your success message here

            } else {
               // Form was submission failed for some reasons.
               // You can examine the response from google to see whats missing

            }
       }).fail(function (jqXHR,status,err) {
            // Form submission failed due to some network or other errors
            // I am alerting the error but you can do anything else with it     
            alert(err);
       });
  });
</script>

请原谅我不整洁的代码...我正在从平板电脑上发布答案。 如果您发现任何问题,请告诉我,以便我修复

【讨论】:

  • 很高兴我能帮上忙
猜你喜欢
  • 1970-01-01
  • 2014-04-17
  • 2017-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-18
  • 2015-05-05
  • 2020-09-04
相关资源
最近更新 更多