1

我有一个用 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; 
}
4

1 回答 1

0

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

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

利用

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

于 2013-08-02T05:13:45.863 回答