在侧边栏中显示表单 [英] Display Form in Sidebar

查看:80
本文介绍了在侧边栏中显示表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我尝试做的事是否可能.

I am not sure if what I am trying to do is even possible.

我正在尝试将Google表单放入Google文档的侧边栏.

I am trying to put a google form into the sidebar of a google doc.

现在,我有一个可以正常打开边栏的apps脚本文档插件,并且可以使用var form = FormApp.openById('form_id');

Right now I have an apps script document plugin that opens the sidebar fine, and I am able to open the form using var form = FormApp.openById('form_id');

但是我不知道如何从表单元素中获取html对象或blob,我可以使用该元素将表单嵌入到边栏中.

But I don't know how to get a html object or blob from a form element that I could use to embed the form in the sidebar.

我也不能使用iframe,因为那是不允许的.

I also can't use iframes as those are disallowed.

推荐答案

尽管您可以在电子表格/文档的边栏中显示google表单(请参见下面的示例代码),但有一个重要的陷阱:表单确实不起作用,即您不能提交表格.不知道确切的原因,但是我想这是由于沙箱限制和/或caja清理.

While you can display a google form in a sidebar in a spreadsheet/document (see sample code below), there is one significant gotcha with it: the form does not work, i.e. you can't submit the form. Not sure exactly why, but my guess it is due to the sandbox restrictions and/or caja sanitization.

我建议您使用HTML和 HTML服务(或 UI服务),然后在边栏中显示该内容.如果您需要将表单保存到电子表格的表单,也可以轻松地做到这一点. 有关在HTML Service中使用表单的信息和代码示例,请参见此内容在UI Service中使用表单.如果您需要这样做,您的服务器端脚本可以打开电子表格并向其中写入表单值.

I suggest you code your own form using HTML and HTML Service (or UI Service) and show that in a sidebar. If you need you form to save the responses to a spreadsheet, you can also do that rather easily. See this for more on info and code samples of using forms in HTML Service and this for using forms in UI Service. Your server-side script can open a spreadsheet and write form values to it, if that's what you need to do.

用于在Google表格的边栏中显示Google表单的附件的示例代码:

注意:该表单实际上无法正常工作-在边栏中显示时不会提交!

function showFormInSidebar() {
  var form = FormApp.openById('YOUR-FORM-ID-HERE');
  var formContent = UrlFetchApp.fetch(form.getPublishedUrl()).getContentText();
  var ui = HtmlService.createHtmlOutput(formContent).setTitle("Google Form in Sidebar Example");
  SpreadsheetApp.getUi().showSidebar(ui);
};

function onOpen(e) {
  // Add this add-on to Add-ons menu
  SpreadsheetApp.getUi().createAddonMenu()
      .addItem('Show form', 'showFormInSidebar')
      .addToUi();
};

这篇关于在侧边栏中显示表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆