2013-08-01 183 views
1

我有一個使用doGet和doPost在Google Apps腳本中編寫的網頁部署表單。在doPost中,代碼檢查用戶是否填寫了正確的表單(例如,沒有將某些東西留空)。如果沒有,則突出顯示需要修復的事項並添加警告標籤。如果一切都正常,它會將表單數據寫入電子表格。doPost兩次Google Apps腳本?

問題是,它似乎不像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; 
} 
+0

請編輯您的問題提供更多的細節。你在使用UiService還是HtmlService?包括一些現有的代碼會有幫助。 – Mogsdad

+0

@villager - 你見過這篇文章(以及它包含的鏈接)http://stackoverflow.com/questions/17620836/create-a-new-page-in-a-form-dynamically-based-on-data-的最上一個頁面。? –

+0

@Sergeinsas,謝謝,但我恐怕我還是不明白。我不需要調用另一個函數,只需重用doGet。 – mrfinnsmith

回答

0

我覺得你只是添加了錯誤的UI元素的應用程序在你的doPost。 而不是

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

使用

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

+0

謝謝,但這似乎並沒有解決問題。 – mrfinnsmith