Emon Hossain
Emon Hossain

Reputation: 388

Post HTML Form Data to Google Spreadsheet

I want to collect response from my portfolio site and save them in a Google spreadsheet. I set up my form and script like this a long ago which work nice:

...
<form id="form" target="_self" onsubmit="return postToGoogle();" action="" autocomplete="off"> 
<input id="nameField" name="entry.2008660880" placeholder="Enter your name" type="text" required> 
<input id="emailField" name="entry.1460631936" placeholder="Enter your email" type="email" required> 
<input id="mobField" name="entry.904964149" placeholder="Enter your 10 Digit Phone Number" type="text" pattern="^\d{10}$" required>  
<button id="send" type="submit" class="common_btn">Send message</button>
</form>
...
<script>
function postToGoogle() {
                var field1 = $("#nameField").val();
                var field2 = $("#emailField").val();
                var field3 = $("#mobField").val();
              
                if(field1 == ""){
                    alert('Please Fill Your Name');
                    document.getElementById("nameField").focus();
                    return false;
                }
                if(field2 == ""){
                    alert('Please Fill Your Email');
                    document.getElementById("emailField").focus();
                    return false;
                }
                if(field3 == "" || field3.length > 10 || field3.length < 10){
                    alert('Please Fill Your Mobile Number');
                    document.getElementById("mobField").focus();
                    return false;
                }
                $.ajax({
                    url: "<googleformURL>",
                    data: {"entry.2008660880": field1, "entry.1460631936": field2, "entry.904964149": field3, "entry.1878256062": field4},
                    type: "POST",
                    dataType: "xml",
                    success: function(d)
                    {
                    },
                    error: function(x, y, z)
                        {

                            $('#success-msg').show();
                            $('#form').hide();
                            
                        }
                });
                return false;
            }
</script>

But now I want to try something similar and find that Google form input has no name or id property.

image

Is there any solution? It will be a great help.

Upvotes: 3

Views: 364

Answers (1)

Devashish
Devashish

Reputation: 1290

Google has made some changes in the way their forms work. To get those same entry.xxxxxxxx values now:

  1. Open your form like you normally do.
  2. On top right corner button, choose option of "pre-filled form link" or something like that.
  3. Now the form that opens can be inspected the same way you did in the past to get the entry.xxxxxx values.

Upvotes: 1

Related Questions