Google 表单响应无法在网站上运行

Google Form Response not working from the website

我正在使用 Google 表单的值与我的网站集成,我想在其中提交表单并将数据存储在 google sheet 中作为表单响应。我正在使用 AJAX 重定向到另一个页面而不是 google 表单提交页面。但是每当我尝试提交时,它都会准确地重定向到我的页面,但数据不会保存在 google sheet 中。这是我的代码,

<strong>Full Name</strong>
<input type="text" name="Fullname" class="form-control" id="Fullname" />
<strong>Email Address</strong>
<input type="text" name="Email" class="form-control" id="Email" />
<strong>Subject</strong>
<input type="text" name="Subject" class="form-control" id="Subject" />
<strong>Details</strong>
<textarea name="Details" rows="8" cols="0" class="form-control" id="Details"></textarea><br />
<button type="button" id="btnSubmit" class="btn btn-info" onclick="postContactToGoogle()">Submit</button>

<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
    function postContactToGoogle() {
        var email = $('#Email').val();
        var fullname = $('#FullName').val();
        var subject = $('#Subject').val();
        var details = $('#Details').val();
        $.ajax({
            url: "https://docs.google.com/forms/d/abcdefgh1234567xyz/formResponse",
            data: {
                "entry_805356472": fullname,
                "entry_1998295708": email, "entry_785075795":
                subject, "entry_934055676": details
            },
            type: "POST",
            dataType: "xml",
            statusCode: {
                0: function () {
                    window.location.replace("Success.html");
                },
                200: function () {
                    window.location.replace("Success.html");
                }
            }
        });
    }
</script>

如何保存googlesheet中的数据?我的代码中遗漏了什么吗?急需帮助?谢谢

如果您转到 Google 上的表单并单击 'View Live Form',然后查看表单上的源代码,您会看到要上传的字段有一个name 形式为 entry.12345678id 的形式是 entry_12345678。您需要使用 name 值。试试这个:

<script>
    function postContactToGoogle() {
        var email = $('#Email').val();
        var fullname = $('#FullName').val();
        var subject = $('#Subject').val();
        var details = $('#Details').val();
        $.ajax({
            url: "https://docs.google.com/forms/d/abcdefgh1234567xyz/formResponse",
            data: {
                "entry.805356472": fullname,
                "entry.1998295708": email, 
                "entry.785075795":  subject, 
                "entry.934055676": details
            },
            type: "POST",
            dataType: "xml",
            statusCode: {
                0: function () {
                    window.location.replace("Success.html");
                },
                200: function () {
                    window.location.replace("Success.html");
                }
            }
        });
    }
</script>

您可以直接从 google view form 页面复制表单,如演示中所示,然后在 AJAX 调用中进行以下更改,如下所示。 现在一旦您提交数据,它就会在 google 表单中可见,查看回复。

$(function(){
    $('input:submit').on('click', function(e){
      e.preventDefault();

        $.ajax({
            url: "https://docs.google.com/forms/d/18icZ41Cx3-n1iW7yTOZdiDx9a6mySWHOy9ryd1l59tM/formResponse",
            data:$('form').serialize(),
            type: "POST",
            dataType: "xml",
            crossDomain: true,
            success: function(data){
              //window.location.replace("youraddress");
              //console.log(data);
            },
            error: function(data){
              //console.log(data);
            }
        });
    });
  });
<div class="ss-form"><form action="https://docs.google.com/forms/d/18icZ41Cx3-n1iW7yTOZdiDx9a6mySWHOy9ryd1l59tM/formResponse" method="POST" id="ss-form" target="_self" onsubmit=""><ol role="list" class="ss-question-list" style="padding-left: 0">
<div class="ss-form-question errorbox-good" role="listitem">
<div dir="auto" class="ss-item  ss-text"><div class="ss-form-entry">
<label class="ss-q-item-label" for="entry_1635584241"><div class="ss-q-title">What's your name
</div>
<div class="ss-q-help ss-secondary-text" dir="auto"></div></label>
<input type="text" name="entry.1635584241" value="" class="ss-q-short" id="entry_1635584241" dir="auto" aria-label="What's your name  " title="">
<div class="error-message" id="1979924055_errorMessage"></div>
<div class="required-message">This is a required question</div>
</div></div></div>
<input type="hidden" name="draftResponse" value="[,,&quot;182895015706156721&quot;]
">
<input type="hidden" name="pageHistory" value="0">

<input type="hidden" name="fvv" value="0">


<input type="hidden" name="fbzx" value="182895015706156721">

<div class="ss-item ss-navigate"><table id="navigation-table"><tbody><tr><td class="ss-form-entry goog-inline-block" id="navigation-buttons" dir="ltr">
<input type="submit" name="submit" value="Submit" id="ss-submit" class="jfk-button jfk-button-action ">
</td>
</tr></tbody></table></div></ol></form></div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>