Skip to content

Instantly share code, notes, and snippets.

@rememberlenny
Last active April 21, 2021 21:30
Show Gist options
  • Save rememberlenny/9de4fdeb5c487ba020fb to your computer and use it in GitHub Desktop.
Save rememberlenny/9de4fdeb5c487ba020fb to your computer and use it in GitHub Desktop.
How to post to Google docs using a jQuery ajax POST request
// url is the link for the form view page
// data is the name attribute of the field
$.ajax({
url: "https://docs.google.com/forms/d/1iqMixtVq4O0AFvYCZHbGerigi1G5Qb3XthXZX9VpNtk/formResponse",
data: { "entry.1679407376": field1},
type: "POST",
dataType: "xml",
statusCode: {
0: function() {
//Success message
},
200: function() {
//Success Message
}
}
});
var request = new XMLHttpRequest();
var d = new Date();
var n = d.getTime();
var url = 'https://docs.google.com/forms/d/1FhRXyqVohna2IdThVwONXLAAGW4f6Ioy46BR2MRZy68/formResponse';
var data = { "entry.993789377": n};
request.open('POST', url, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.send(data);
@hiramanpatil
Copy link

Hi,

Thank you for the code. I have tried with both the options but unable to save the form data into the google sheet. Though I get the success message (statusCode - 0) but response doesnt get recored into the sheet.

Is there anything which needs to be configured in a google form or response sheet to save data using AJAX request?

Thanks,

@kevinlaiGH
Copy link

Hi,

Could anyone explain to me what line 7 is about?

data: { "entry.1679407376": field1},

What is entry.1679407376?

Cheers

@ArtiomNomi
Copy link

"entry.1679407376" is the key of the field provided by google form

@shamshul2007
Copy link

If the google form have email filed then there is no entry ...what I have to pick in that case and what has to be passed into data{ }

@rememberlenny
Copy link
Author

@shamshul2007 Sorry I dont quite understand your issue. The data values can be found by looking at the google form using developer console and identifying the field's ID value.

@shamshul2007
Copy link

@rememberlenny In case for the email field in the form. There is no entry field ID which I checked the view source.

@bitttttten
Copy link

bitttttten commented Sep 15, 2020

Running into the same issue as @shamshul2007

When you explicitly "collect email addresses" then there is no "entry.x" id on the form. It looks like google form is using "emailAddress" as the name, although this doesn't work when I send emailAddress as the key.

Did you find out a solution @shamshul2007?

@TanimSk
Copy link

TanimSk commented Apr 21, 2021

after creating form click three dots> go to get prefilled link>then inspect
you will get the input fields name

@rememberlenny
Copy link
Author

I'm surprised people still use this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment