google-spreadsheet Add a Google Form to a web page Manage the dialog box and google form iframe


Example

Add a new function called showGoogleForm and adapt the follow code to suit. Note for simplicity this example does not contain any error checking which should be added in a production environment.

The url should look something like this: https://docs.google.com/forms/.../?usp=pp_url&entry.1739103583=labelname1

  var showGoogleForm = function (e) {
    var url = e.currentTarget.googleFormsURL
    url = url.replace('labelname1', 'Some prefilled value')
    url = url.replace('labelname2', 'Another prefilled value')

    // Add the iFrame dynamically to avoid popup issue
    jQuery('<iframe id="#googleform" src="" width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>').appendTo('#googleformparent')    

    // Set the prefilled url as the iFrame source
    jQuery('#googleform').attr('src', url)

    // Remove the iframe element when the user closes the dialog to avoid the popup if the user did not submit the form.
    jQuery('#dialogclose').click(function(e) {
        jQuery('#googleform').remove()        
    })

  }