Click here to Skip to main content
15,314,965 members
Articles / Programming Languages / Javascript
Posted 5 Feb 2014


27 bookmarked

Store your form data in Google Spreadsheet

Rate me:
Please Sign up or sign in to vote.
4.81/5 (12 votes)
23 Jun 2014CPOL2 min read
This is probably the simplest solution for storing web form data into database. We will use Google Forms and Google Spreadsheets as our 'database'.


HTML <form> tag is available as a part of HTML from the beginning of the Internet. It is used on web pages to collect data from the users. After clicking Submit button, form data is sent to server, which usually stores them in one of the databases. While use of <form> tag is easy, server side part can be sometimes challenging to set up and operate. In this tip, I will show how we can use Google Docs Forms and Google Docs Spreadsheets as our 'database' for saving user inputs.

Using the Code

To use Google Forms and Spreadsheets as your server 'database', you will need to complete some easy steps. Google account is required to complete this task.

  1. Go to and create a new form. In my sample, I have created form with the following fields: Email, Firstname, LastName and Company. To keep this simple, I've set all fields to type text and without any validation rules.

    Image 1

  2. Click 'View Live Form' button and check the source of the form that is shown. As the source might not be very easy to read and understand, you will have to find a lot of information. First one is the form post URL. Search for '<form action' and mind URL in action value:
    <form action="" 
    method="POST" id="ss-form" target="_self" 
    onsubmit=""><ol style="padding-left: 0"> 
  3. Find the unique names of each field. In my case, we have four different form fields. Look for the field name and mind for <input> tags. Attribute name is the parameter that we will need. Name value start with the 'entry.' keyword. The name of the email field in my example is entry_1402836733.
    <input type="text" name="entry.1402836733" 
    value="" class="ss-q-short" id="entry_1402836733" 
    dir="auto" aria-label="Email  " title=""> 

    You will need to find names of all the form field.

  4. This is all the information you need. Now let's make our own form in HTML file. You can put the code below into the <body> tag.
    <input id="Email" name="Email" 
    type="text"  placeholder="Email Address">
    <input id="First" name="First" 
    type="text"  placeholder="First Name">
    <input id="Last" name="Last" 
    type="text"  placeholder="Last Name">
    <input id="Company" name="Company" 
    type="text" placeholder="Company">
    <button id="ButtonSubmit" onclick="postContactToGoogle()" 
    type="button" >Send</button> 
  5. In the final step, we will create JavaScript function that will post data to Google Form. In order to work, you need to reference jQuery.
        function postContactToGoogle() {
            var email = $('#Email').val();
            var first = $('#First').val();
            var last = $('#Last').val();
            var company = $('#Company').val();
                    url: "",
                    data: { "entry_1402836733": email,
                    "entry_1874720748": first, "entry_2092106103":
                    last, "entry_944373055": company },
                    type: "POST",
                    dataType: "xml",
                    statusCode: {
                        0: function () {
                        200: function () {

    Code is actually simple once we collected relevant data from Google Form source. First, I use jQuery to get user inputs and we store them in local variables. Then I initiate Ajax POST call to the URL from Google Form source. URL is called with key-value parameters. After I receive statusCode from server, I redirect to browser to another page.

Points of Interest

I found that Google Forms and Google Spreadsheets can be an excellent database foundation form small scale projects and prototypes. Doing data collection this way, it is easy to share the responses.


I never liked history teachers. Wink | ;)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Dejan Mauer
Software Developer (Senior) CENT SI d.o.o.
Slovenia Slovenia
I have strange hobby - programming.
While I am not programming I am tasting some good beers Wink | ;)

Comments and Discussions

Questionprevent blank form submits Pin
Srinivas0829-Oct-19 23:13
MemberSrinivas0829-Oct-19 23:13 
QuestionHow could I capture checkboxes values Pin
jafaruddeen7-Nov-17 20:15
Memberjafaruddeen7-Nov-17 20:15 
QuestionNot able to get it to work - can you help? Pin
Member 123062223-Feb-16 13:33
MemberMember 123062223-Feb-16 13:33 
AnswerRe: Not able to get it to work - can you help? Pin
Member 123642092-Mar-16 1:15
MemberMember 123642092-Mar-16 1:15 
GeneralRe: Not able to get it to work - can you help? Pin
Aaron Shier9-Mar-16 21:03
MemberAaron Shier9-Mar-16 21:03 
QuestionDoesn't work with explorer and firefox browsers Pin
Member 120931691-Nov-15 22:04
MemberMember 120931691-Nov-15 22:04 
QuestionAdd coordinates from google map Pin
4swat44-Aug-15 2:51
Member4swat44-Aug-15 2:51 
GeneralRegarding Post save form data to Google Spread sheet Pin
Member 1170442919-May-15 20:42
MemberMember 1170442919-May-15 20:42 
GeneralRe: Regarding Post save form data to Google Spread sheet Pin
Member 1185498422-Jul-15 7:01
MemberMember 1185498422-Jul-15 7:01 
QuestionHow to work with Non-textbox elements? Pin
Member 1160372313-Apr-15 22:59
MemberMember 1160372313-Apr-15 22:59 
Questionshould this create a spreadsheet in my google drive ? Pin
mlotfi11-Apr-15 18:21
Membermlotfi11-Apr-15 18:21 
QuestionPlease help nothing work when run code Pin
Member 1039550427-Feb-15 23:51
MemberMember 1039550427-Feb-15 23:51 
AnswerRe: Please help nothing work when run code Pin
Member 123062223-Feb-16 13:34
MemberMember 123062223-Feb-16 13:34 
Member 1039550421-Feb-15 17:56
MemberMember 1039550421-Feb-15 17:56 
BugI am getting an Access-Control-Allow-Origin Pin
Ubaier Bhat7-Feb-15 12:02
MemberUbaier Bhat7-Feb-15 12:02 
Questionsame problem. Pin
Ankan Seth31-Jan-15 11:20
MemberAnkan Seth31-Jan-15 11:20 
QuestionCool, but... Pin
Member 1140040224-Jan-15 21:39
MemberMember 1140040224-Jan-15 21:39 
QuestionName or ID? Pin
Member 1106522626-Sep-14 4:06
MemberMember 1106522626-Sep-14 4:06 
QuestionWindow location / page to apear after submit Pin
Member 1101982718-Aug-14 5:15
MemberMember 1101982718-Aug-14 5:15 
AnswerRe: Window location / page to apear after submit Pin
Member 1185498422-Jul-15 6:59
MemberMember 1185498422-Jul-15 6:59 
GeneralMy vote of 5 Pin
khanhamid92215-Jul-14 11:51
Memberkhanhamid92215-Jul-14 11:51 
GeneralMy vote of 4 Pin
Brian A Stephens26-Jun-14 2:42
professionalBrian A Stephens26-Jun-14 2:42 
GeneralRE: Store your form data in Google Spreadsheet Pin
Unka_Georgr24-Jun-14 7:19
professionalUnka_Georgr24-Jun-14 7:19 
QuestionThis is not working for me - nothing is getting saved to the google doc Pin
Member 1082256215-May-14 20:56
MemberMember 1082256215-May-14 20:56 
AnswerRe: This is not working for me - nothing is getting saved to the google doc Pin
Dejan Mauer15-May-14 23:10
MemberDejan Mauer15-May-14 23:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.