1
votes

I have a web-deployed form written in Google Apps Script with doGet and doPost. In the doPost, the code checks if the user has filled in the form correctly (e.g. not leaving certain things blank). If not, it highlights the things that need to be fixed and adds a warning label. If everything is all right, it writes the form data to a spreadsheet.

The problem is that it doesn't seem like doPost can be called again if the user fixes the problems.

Any thoughts? Thanks!

EDIT: I am using UiService EDIT: Here is a very simplified version of the app:

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; 
}
1
Please provide more details by editing your question. Are you using UiService or HtmlService? Including some existing code would help.Mogsdad
@villager - Have you seen this post (and the links it contains ) stackoverflow.com/questions/17620836/….?Serge insas
@Sergeinsas, thanks, but I'm afraid I still don't understand. I don't need to call another function, just reuse the doGet.mrfinnsmith
What I'm having trouble with is that fileUpload at times only works in a doPost (and other times in other functions), but I can only return to the original app if I don't call doPost. I'd like to have both text boxes and fileuploads, validate the user's entries when the user hits the button, then allow the user to correct any errors and resubmit. At THAT point, I'd like to call various other functions based on the information that the user has submitted.mrfinnsmith

1 Answers

0
votes

I think you are just adding the wrong UI element to the app in your doPost. Instead of

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

use

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