谷歌电子表格网站表单jQuery脚本阻止发送

Google spreadsheet website form jQuery script block the sending of

本文关键字:脚本 jQuery 电子表格 网站 表单 谷歌      更新时间:2023-09-26

我的表格是html格式的。我从原始的Google表单中复制了操作,输入键和隐藏输入。

<form id="Gform" role="form" action="https://docs.google.com/forms/d/MY-FORM-KEY/formResponse" method="POST" target="_self" onsubmit="">
                <input type="text" pattern="^[a-zA-Z][a-zA-ZążźćśęółbńĄŻŹĆŃŚĘÓŁ ]{4,40}$" name="entry.1028663680" value="" id="entry.1028663680" dir="auto" title="What is Your city" class="form-control" placeholder="City" required>
                <input type="text" pattern="^[a-zA-Z][a-zA-ZążźćśęółbńĄŻŹĆŃŚĘÓŁ ]{5,40}$" name="entry.1220908348" value="" id="entry.1220908348" dir="auto" title="Your complete name" class="form-control" placeholder="Your name" required>
                <input type="tel" name="entry.623688995" value="" id="entry.623688995" dir="auto" title="" class="form-control" placeholder="phone" required>
                <input type="email" name="entry.1564973803" value="" id="entry.1564973803" dir="auto" title="" class="form-control" placeholder="email" required>
                <input type="hidden" name="entry.383122401" value="WEBSITE" id="entry.383122401" dir="auto" title="" class="form-control" placeholder="E-mail" required>
                <input type="hidden" name="draftResponse" value="[,,&quot;-9139933475238999509&quot;]
">
<input type="hidden" name="pageHistory" value="0">
<input type="hidden" name="fbzx" value="-9139933475238999509">
                <button type="submit" name="submit" id="sendData" class="btn btn-default">Submit</button>
            </form>

我有 te jQuery 脚本,它显示确认:

    <script type="text/javascript">
    function sendContactForm(){
                $("#Gform").fadeOut();
                $("#form-container").append('<p class="confirmer">Thanks!<br>Your email was sent.</p>');
           };
$('#Gform').submit(function () {
 sendContactForm();
 return false;
});
</script>

当我删除此脚本时,表单正在发送并保存到谷歌,但在点击提交后,我重定向到谷歌"谢谢"页面。我不想像

在脚本中一样重定向和显示确认。如何解决这个问题?

尝试使用

AJAX 来完成您的任务,当您使用异步函数时,不会有重新加载页面,您将在幕后发送数据。在数据对象中输入所有输入值,在 done(( 和 fail(( 函数中定义收到响应时要执行的操作。祝你好运:(

$('#formID').submit(function(e){
   e.preventDefault();
   $.ajax({
      url: "https://docs.google.com/forms/d/1PrgHQALlz0WrvwjhGpLrtIgD5aQ1x-8HrOubkxTLNKs/formResponse",
      type: "POST",
      data: {
         'entry.111':     $('#entry_111').val(),
         'entry.222': $('#entry_222').val(),
        // all data from form
      }
   }).done(function(data){
      yourAction(data);
   }).fail(function(data){
      failAction(data);
   });
});

注释上面代码中的return false

$('#Gform').submit(function () {
    sendContactForm();
    //return false;
});

或者只是删除此行。这是脚本正在做的是:订阅submit事件并取消它。

你想做点别的吗?