Google Forms: Submitting Data to a Spreadsheet

How can I submit data from a web form to google spreadsheet? I made a form with Google Drive, but in order to run custom CSS, I need to copy the form tag.

In my case, this is what Google created for the behavior of the submit button

<form action="https://docs.google.com/forms/d/113H_71nd98TWE0bByjHYNpnC- oVA6OBDWtppU30rBrU/formResponse" method="POST" id="ss-form" target="_self" onsubmit=""> 

However, I want to post data from my own developed form to the above Google Form answer spreadsheet. Here is my form code (using Bootstrap 3):

 <form class="form-horizontal" role="form" id="ftk-contact"> <h4>Get in touch with us now</h4> <div class="form-group"> <label for="inputType" class="col-lg-2 control-label">Type of Inquiry</label> <div class="col-lg-10"> <select class="form-control" id="inputType"> <option>Request a Quotation</option> <option>Request a Bluebook</option> <option>General Inquiry</option> </select> </div> </div> <div class="form-group"> <label for="inputName" class="col-lg-2 control-label">Name *</label> <div class="col-lg-10"> <input type="text" class="form-control" id="inputName" placeholder="Your Name"> </div> </div> <div class="form-group"> <label for="inputEmail" class="col-lg-2 control-label">Email *</label> <div class="col-lg-10"> <input type="email" class="form-control" id="inputEmail" placeholder="Your Email"> </div> </div> <div class="form-group"> <label for="inputCompany" class="col-lg-2 control-label">Company</label> <div class="col-lg-10"> <input type="text" class="form-control" id="inputCompany" placeholder="Your Company Name"> </div> </div> <div class="form-group"> <label for="message" class="col-lg-2 control-label">Message *</label> <div class="col-lg-10"> <textarea class="form-control" rows="5" placeholder="Your Message"></textarea> </div> </div> <div class="form-group"> <label for="inputPhone" class="col-lg-2 control-label">Phone</label> <div class="col-lg-10"> <input type="tel" class="form-control" id="inputPhone" placeholder="Your Phone Number"> </div> </div> <div class="form-group"> <label for="inputWeb" class="col-lg-2 control-label">URL</label> <div class="col-lg-10"> <input type="url" class="form-control" id="inputWeb" placeholder="Your Website URL"> </div> </div> <div class="form-group"> <div class="col-lg-offset-2 col-lg-10"> <button type="submit" class="btn btn-primary btn-lg">Send your Inquiry now</button> </div> </div> </form> 

Using the Google form above action = ... I accept the original Google form when I click send instead of the records in the form that are copied to the spreadsheet.

If the above approach does not work, how else can I send the form data to email or to Google Drive?

+8
html twitter-bootstrap forms google-drive-sdk
source share
7 answers

Here is what worked for me:

  • Create your own form
  • Create your Google form and view the source code after clicking the live button
  • Copy the html code from <form> to </form>
  • Each of the input fields on a Google form has name and identifier attributes that you need to copy into your personal form.
  • Use the URL in the form of the Google forms in your form.
  • Make sure that even the submit button has identifier and name attributes that match the source of the Google form.
  • If you are submitting an application now, it will take you to the answer page of the Google form. You can avoid this by submitting an ajax form.

If your custom form doesn’t confirm the required element of the Google form, you will again be redirected to the Google form page.

+15
source share

Complete step by step instructions

After reading Martin Howski a good presentation (for sending data from an HTML form to a Google spreadsheet) and looking at a few spaces / assumptions, we decided to write a detailed / comprehensive guide with step-by-step instructions that several people found useful:

https://github.com/dwyl/ html -form- send -email -via- google- script -without server

The script saves any data sent via HTTP POST in a Google spreadsheet, and possibly redirects the content to an email address. (useful if you want to be notified of new data)

HTML form:

contact form

Result (line in sheet):

row in sheet

We commented on the Google script, so hopefully this is clear, but if you have any questions, feel free to ask !:-)

+5
source share

I added a utility called Magic Forms to add additional features beyond those offered by Google endpoints. Create a magic form project, and it will provide you with an HTTP endpoint where you can receive POST forms (regular HTTP or Ajax), configure redirection for success / error, and automatically create columns based on any data that is published, which allows Some pretty flexible use cases.

+3
source share

It looks like Google recently updated its way to create forms, so now the field names are in hidden entries below the regular ones ( https://github.com/heaversm/google-custom-form ).

I also tried the @nelsonic approach and it sends the responses in JSON format correctly, but it does not upload them to the Google spreadsheet, at least for me. This is why I wanted to combine the two methods in order to always save user data in case of more obfuscation changes that will be made by Google in the future.

Therefore, I recommend that you have a webpage with an iframe inside it. This iframe will contain your own custom form, from another web page or, as in my example, for convenience, by itself, using the srcdoc attribute.

Then you copy the names hidden inputs as well as the action URL on the Google Form Preview page. > and paste them into your custom form.

And finally, with Ajax, we can easily send one copy of the form data to a regular Google spreadsheet, and another to our mail using the @nelsonic script solution.

Thus, with iframe and Ajax, we avoid redirecting URLs to the Registered Response page when the form is submitted to Google, but we can hide the iframe from the parent view to be 100% sure.

I have posted all my code here for verification:

Google Spreadsheet with @nelsonic solution: https://docs.google.com/spreadsheets/d/1LUcidZln8fk-VymjyOXX4gfVusmCf8-G-SghraOPNyA/edit?usp=sharing

Custom form:

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Custom Form to Google SpreadSheets</title> </head> <body> <script type="text/javascript"> function hideIframeAndShowThankYouMessage(){ document.getElementById('iframe').style.display = "none"; document.getElementById('thankyou').style.display = "block"; } </script> <iframe id="iframe" width="760" height="500" frameborder="0" marginheight="0" marginwidth="0" srcdoc="<html><head></head><body> <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script> <script type='text/javascript'> $(document).ready(function(){ $('#form').submit(function(e) { // You could also here, for example, valid an email address input // It shouldn't appear, but just in case the iframe loads the Google Forms 'Answer registered' page, we hide the iframe from parent js: window.top.hideIframeAndShowThankYouMessage(); // Now we send the same form to two different locations: the first is the ordinary Google Spreadsheet, the second is the Google Apps Script which allows us to receive an email with the form info in JSON format var url_sheet = 'https://docs.google.com/forms/d/e/1FAIpQLSdxucfxPO2TgTh4DOKTty6VCykJ6v4RX0nbKjsz1Pc5fLR9gA/formResponse'; var url_script = 'https://script.google.com/macros/s/AKfycby2xOphkRsr8Uf3mD44-H68yC0U3bUqvKV0bxXrTISTQ7QKDxw/exec'; $.ajax({ type: 'POST', url: url_sheet, data: $('#form').serialize(), success: function(data){} }); $.ajax({ type: 'POST', url: url_script, data: $('#form').serialize(), success: function(data){} }); e.preventDefault(); }); }); </script> <!-- *** TO-DO!! *** 1. Copy your form ACTION url from your Google Form Preview Page 2. Replace value of var url_sheet with that form ACTION url in line 31 3. Copy your Spreadsheet WEB APP url from Google Script Editor 4. Replace value of url_script with that WEB APP url in line 33 3. Look into the source of your Google Form Preview Page and search for the names of the HIDDEN fields which are each one close to the normal input type (... <input type='hidden' name='entry.314619096' jsname='L9xHkb'> ...). We don't need the jsname, only the name 4. Replace the NAMES fields of every field of the custom form below --> <form id='form' method='POST'> <label for='name'>Name: </label> <input type='text' name='entry.314619096' placeholder='This is easy!' /> <br/> <label for='message'>Message:</label> <input type='text' name='entry.2039301116' placeholder='Tell me something! ;)'/> <br/> <input type='submit' value='Submit'> </form></body></html>">Loading...</iframe> <h1 id="thankyou" style="display: none">Thank you!</h1> </body> </html> 

Hope this helps someone!

+3
source share

You can copy the HTML form created by Google and include it in a custom HTML page. Thus, you can change the appearance of the Google form as you want, and using jQuery or similar methods, you can add your own form to the form (if necessary).

You have an example: http://www.immersionmedia.com/blog/customizing-and-styling-google-forms/

+2
source share

It is very simple.

  • Get your form identifier from the “action” property in FORM, you can get the form tag in the source of the Google Form web page

  • Get Ex field identifiers. "Entry.1472837636"

Below is an example below.

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>CUSTOM GOOGLE FORM</title> </head> <body> <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <form id="input-form" action="" method="POST" target="no-target"> <table> <tr> <td>Rate this help note</td> <td><input type="radio" value="1" name="rating" class="rating" checked="">1</td> <td><input type="radio" value="2" name="rating" class="rating">2</td> <td><input type="radio" value="3" name="rating" class="rating">3</td> <td><input type="radio" value="4" name="rating" class="rating">4</td> <td><input type="radio" value="5" name="rating" class="rating">5</td> <td><input type="radio" value="6" name="rating" class="rating">6</td> <td><input type="radio" value="7" name="rating" class="rating">7</td> <td><input type="radio" value="8" name="rating" class="rating">8</td> <td><input type="radio" value="9" name="rating" class="rating">9</td> <td><input type="radio" value="10" name="rating" class="rating">10</td> </tr> <tr> <td>Are you satisfied from this help module ?</td> <td><input type="radio" value="Yes" name="sat" class="sat" checked="">Yes</td> <td><input type="radio" value="No" name="sat" class="sat">No</td> </tr> <tr><td>comments</td><td><input id="comments" name="comments"><td></tr> <tr><td><button id="form-submit" type="submit">SUBMIT</button></td></tr> </table> </form> <p id="input-feedback"></p> <iframe src="#" id="no-target" name="no-target" style="visibility:hidden"></iframe> <script> jQuery('#input-form').one('submit', function() { var rating = encodeURIComponent(jQuery('input[name=rating]:checked').val()); var sat = encodeURIComponent(jQuery('input[name=sat]:checked').val()); var comments = encodeURIComponent(jQuery('#comments').val()); var q1ID = "your-field-id"; var q2ID = "your-field-id"; var q3ID = "your-field-id"; var baseURL = 'https://docs.google.com/forms/d/e/your-form-id/formResponse?'; var submitRef = '&submit=Submit'; var submitURL = (baseURL + q1ID + "=" + sat + "&" + q2ID + "=" + rating + "&" + q3ID + "=" + comments + submitRef); console.log(submitURL); jQuery(this)[0].action = submitURL; jQuery('#input-feedback').text('Thank You!'); }); </script> </body> </html> 
+1
source share

I struggled with this from the last few days, nothing worked. In the end, I found a very good solution.

 var sheetName = 'Sheet1' var scriptProp = PropertiesService.getScriptProperties() function intialSetup () { var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet() scriptProp.setProperty('key', activeSpreadsheet.getId()) } function doPost (e) { var lock = LockService.getScriptLock() lock.tryLock(10000) try { var doc = SpreadsheetApp.openById(scriptProp.getProperty('key')) var sheet = doc.getSheetByName(sheetName) var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0] var nextRow = sheet.getLastRow() + 1 var newRow = headers.map(function(header) { return header === 'timestamp' ? new Date() : e.parameter[header] }) sheet.getRange(nextRow, 1, 1, newRow.length).setValues([newRow]) return ContentService .createTextOutput(JSON.stringify({ 'result': 'success', 'row': nextRow })) .setMimeType(ContentService.MimeType.JSON) } catch (e) { return ContentService .createTextOutput(JSON.stringify({ 'result': 'error', 'error': e })) .setMimeType(ContentService.MimeType.JSON) } finally { lock.releaseLock() } } 

Click here for more information.

0
source share

All Articles