【问题标题】:doPost Twice in Google Apps Script?在 Google Apps 脚本中发布两次?
【发布时间】:2013-08-01 18:53:22
【问题描述】:

我有一个用 Google Apps 脚本编写的 web 部署表单,带有 doGet 和 doPost。在 doPost 中,代码检查用户是否正确填写了表单(例如,不将某些内容留空)。如果没有,它会突出显示需要修复的内容并添加警告标签。如果一切正常,它将表单数据写入电子表格。

问题在于,如果用户解决了问题,似乎无法再次调用 doPost。

有什么想法吗?谢谢!

编辑:我正在使用 UiService 编辑:这是应用程序的一个非常简化的版本:

function doGet(e) {
  var app = UiApp.createApplication();
  var mainForm = app.createFormPanel().setId('mainForm');
  var formContent = app.createVerticalPanel().setId('formContent');
  var userName = app.createTextBox().setId('userName').setName('userName');
  var passport = app.createFileUpload().setName('passport');
  var submitButton = app.createSubmitButton('submit here');  
  var submitButtonWarning = app.createLabel('Something is wrong.').setId('submitButtonWarning')
  .setVisible(false);

  formContent
  .add(userName)
  .add(passport)
  .add(submitButton)
  .add(submitButtonWarning);

  mainForm.add(formContent);
  app.add(mainForm);
  return app;
}

function doPost(e) {
  var app = UiApp.getActiveApplication();
  var userName = e.parameter.userName;
  var passport = e.parameter.passport;
  if (userName == 'no') {
    app.getElementById('submitButtonWarning').setVisible(true);
    app.add(app.getElementById('formContent'));
    return app;
  } else {
    app.getElementById('submitButtonWarning').setVisible(false);
    app.add(app.getElementById('formContent'));
    return app;
  }
  return app; 
}

【问题讨论】:

  • 请通过编辑您的问题提供更多详细信息。您使用的是 UiService 还是 HtmlService?包括一些现有的代码会有所帮助。
  • @villager - 你看过这篇文章(以及它包含的链接)stackoverflow.com/questions/17620836/….?
  • @Sergeinsas,谢谢,但恐怕我还是不明白。我不需要调用另一个函数,只需重用 doGet。
  • 我遇到的问题是 fileUpload 有时只能在 doPost 中工作(有时在其他函数中),但如果我不调用 doPost 我只能返回原始应用程序.我想同时拥有文本框和文件上传,在用户点击按钮时验证用户的输入,然后允许用户更正任何错误并重新提交。此时,我想根据用户提交的信息调用各种其他函数。

标签: google-apps-script google-apps


【解决方案1】:

我认为您只是在 doPost 中向应用程序添加了错误的 UI 元素。 而不是

app.add(app.getElementById('formContent'));

使用

app.add(app.getElementById('mainForm'));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多