5

I'm looking for a way to take specific fields from a Google Form and input it into an html page.

  <form>
      <input id="email" type="text" placeholder="email address" value="email">
      <button id="submit" type="submit">Submit</button>
  </form>

When I click submit, I want that data to submit to a specific Google form.

Thanks

1 Answer 1

14

If you want to build your own form, hosted separately from Google, and submit to a Google Form, you need to emulate the Google Form's POST request. First, you need to get the form data that's being sent to Google and then you need to submit it from your own page using AJAX.

To get the form data, open Chrome's Developer tools and click the Network tab. Then submit your Google-hosted form with dummy data. Click on the first item you see in the list - it should say "formResponse". Then you need to copy two things from the data on the right-hand pane: "Request URL" (where your own form will submit) and anything beginning with "entry." in the Form Data section (e.g., "entry.123456").

Next, build a form on your own page, and use AJAX to submit the data to Google. The way I've done it is to use jQuery to hijack the form submission so that your form doesn't try to submit to your own domain:

$('.my-form').on('submit', function() {
  e.preventDefault(); 
  $.ajax(
    type:"POST"
    url: "https://docs.google.com/forms/d/your-form-id/formResponse"
    data: {
      'entry.12345': $('.your-form-input').val()
    }
  );
}
3
  • What is the e in e.preventDefault();?
    – jado
    May 21, 2015 at 19:43
  • 1
    'submit', function(e) { it's an event argument to a function Feb 5, 2017 at 22:55
  • I wanted to add that Google Forms has made it slightly harder to find the entry.XXXXXXXXXX code that you need. I made a write-up on this. Hopefully it is useful to anyone seeing this in 2020 dev.to/ninest/natively-embed-google-forms-in-your-website-57g3
    – themthem
    Aug 3, 2020 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.