Home > Net >  How can I create a popup google form in google sheets?
How can I create a popup google form in google sheets?

Time:05-06

I am looking to create a popup google form that appears when you press a menu item in the sheet. I can get it to show but I can't answer the questions.

Here is my current code:

function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menubuttons1 = [ {name: "Input", functionName: "ask"} ];
ss.addMenu("Sales", menubuttons1);
}

function ask() {
var form = FormApp.openById("1LdHO6bazGUsrmanRUbUwj28-gTiv2pJwUEfj8NzinjA"),
    formUrl = form.getPublishedUrl(),
    response = UrlFetchApp.fetch(formUrl),
    formHtml = response.getContentText(),
    htmlApp = HtmlService
  .createHtmlOutput(formHtml)
  .setSandboxMode(HtmlService.SandboxMode.IFRAME)
  .setTitle('Sales Input')
  .setWidth(450) 
  .setHeight(500);  SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}

And here is the google sheet and form:

Sheet: https://docs.google.com/spreadsheets/d/1aGkZjDgMkRrFiPqCy5zy-bORGxuPKnSgYzP0vhy4bso/edit#gid=0

Form: https://docs.google.com/forms/d/1LdHO6bazGUsrmanRUbUwj28-gTiv2pJwUEfj8NzinjA/edit

CodePudding user response:

In your situation, how about the following modification?

Modified script:

In this modification, I modified the function ask.

function ask() {
  var form = FormApp.openById('1LdHO6bazGUsrmanRUbUwj28-gTiv2pJwUEfj8NzinjA');
  var formUrl = form.getPublishedUrl();
  var formHtml = `<iframe id="inlineFrameExample" src="${formUrl}" style="border:none; width:400px; height:400px;"></iframe>`;
  var htmlApp = HtmlService
    .createHtmlOutput(formHtml)
    .setSandboxMode(HtmlService.SandboxMode.IFRAME)
    .setTitle('Sales Input')
    .setWidth(420)
    .setHeight(420);
  SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}
  • Related