Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Google Forms without iframe?

Some years ago, I found on internet how to use Google forms inside a contact page only using a query in the attribute submit button action without iframe. Now, I can't find it anymore. Is it still possible to use Google forms without iframe?

like image 807
Paulo Dos Santos Avatar asked Nov 12 '16 08:11

Paulo Dos Santos


People also ask

Can you integrate a Google form into a website?

Use Forms to add a survey or form to your Sites page Go to Formsand open your form. Click Send. Click the HTML and click Copy. Paste the HTML into your site or blog.

How do I use Google Forms in HTML?

You can embed Google Forms from the desktop website. Go to Google Forms, open the form you want to embed and click the "send" button on the top right of screen. Adjust the height and width of the embed and click "copy" to copy the HTML code. You can then paste the code on your website or blog.

Can you iframe Google Forms?

Embedding Google FormsYou can create a Google form and simply embed it in your page with the <iframe> tag. To do this, after creating the form on Google Docs, click on File | Embed and then copy the provided HTML. Paste it on your page. That's it.


1 Answers

I just found it!

 function postToGoogle() {
   var field1 = $("input[type='radio'][name='qs1']:checked").val();
   var field2 = $('#feed').val();

   $.ajax({
     url: "https://docs.google.com/forms/d/e/1FAIpQLSdjOTKRb7YiWi8OGPq6M6CRL0TpuAsUKacKp2XgruMbIp4wzg/formResponse",
     data: {
       "entry.924752166": field1,
       "entry.997497831": field2
     },
     type: "POST",
     dataType: "xml",
     statusCode: {
       0: function() {
         //Success message
       },
       200: function() {
         //Success Message
       }
     }
   });
 }

/* 
$(document).ready(function() {
   $('#form').submit(function() {
     postToGoogle();
     return false;
   });
   
});
*/
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<strong>Test Google Form</strong>
<form id="form" target="_self" onsubmit="" action="javascript: postToGoogle()">
  <fieldset>
    <label>Question 1</label>
    <input id="qs1_op_1" type="radio" value="Yes" name="qs1" />
    <input id="qs1_op_2" type="radio" value="No" name="qs1" />
  </fieldset>

  <fieldset>
    <label>Text</label>
    <textarea id="feed" name="feed"></textarea>
  </fieldset>
  <div style="width: 100%; display: block; float: right;">
    <button id="send" type="submit">
      Send
    </button>
  </div>
</form>
<br /><br />
The <a href="https://docs.google.com/spreadsheets/d/1bVeLfK2gm6emaGRKHnMllpeb_P4HwwZoIfZB5MCcyZg/pubhtml">Result</a> takes few minutes to be shown, but it is sent to the google sheet instantaneously. 
<br /><br />

It's working in CodePen.

like image 118
Paulo Dos Santos Avatar answered Oct 05 '22 18:10

Paulo Dos Santos