Reputation: 173
This function in a google sheet does popup a window with the form, but the submit button is dead. What is missing that will make this window a live one?
function launchForm() {
var formID = '1YznrnFFIfXLpsZfsIZ4xjhlwmi8eLv_nTuOjDKGhwIc';
var form = FormApp.openById(formID);
var formUrl = form.getPublishedUrl();
var response = UrlFetchApp.fetch(formUrl);
var formHtml = response.getContentText();
var htmlApp = HtmlService
.createHtmlOutput(formHtml)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Ta Daaa!')
.setWidth(500)
.setHeight(650);
SpreadsheetApp.getUi().showModalDialog(htmlApp, 'Query window');
}
The function is hooked to a menu item and clicking on that item does bring up the form over the sheet, as does running the script from the script project attached to the sheet.
menuEntries.push({name: "Launch Query form", functionName: "launchForm"});
This particular form is simple, only three fields. So I could consider using HTML service to build an HTML and I see lots of questions about that not working either, so I can probably work that out. However, I have other forms that are a lot more complex and being able to simply call a regular Google form from within the spreadsheet is what I'd rather do.
Upvotes: 1
Views: 1998
Reputation: 31300
Embed the URL of the Google Form into the HTML of the dialog box:
function launchForm() {
var htmlApp = HtmlService
.createHtmlOutputFromFile('InputForm')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Ta Daaa!')
.setWidth(500)
.setHeight(650);
SpreadsheetApp.getUi().showModalDialog(htmlApp, 'Query window');
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<iframe src="https://docs.google.com/forms/d/e/FormIDHere/viewform?embedded=true" width="760" height="500" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>
</body>
</html>
In "New" Google Forms you can get the IFRAME tag to embed the Google Form by clicking the "Send" button at the top right, and then clicking the third tab "<>"
Upvotes: 1