I'm teaching myself Javascript and needed an explanation on old post that I found very helpful. I apologize in advance if this may seem like a sophomoric post on stackoverflow.
I am referencing this post: Google Apps Script Create form with file upload
I have used the script and am trying to learn it because I have high school students who want to create a google webapp to gather data and information for their projects. Of course I have to learn it myself and explain it. There are two sections I am unsure of. Here's the Code.
var submissionSSKey = '0Agd12jO_f4DrdFFYemZvRERvLWQ4UEhENllaWlVwOFE';
var listitems = ['Select a category','Portrait','Landscape','Night shots','Nature','Various']
var schoollist =['Select School','AFNORTH','Baumholder','Bamberg','Lakenheath MS']
var Panelstyle = {'background':'#dddddd','padding':'40px','borderStyle':'ridge','borderWidth':'15PX','borderColor':'#aaaaaa'}
function doGet() {
var app = UiApp.createApplication().setTitle('i14 Art Submission').setStyleAttribute('padding','50PX');
var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400, 200);
var title = app.createHTML('<B>I14 Art Submission</B>').setStyleAttribute('color','grey').setStyleAttribute('fontSize','25PX');
var grid = app.createGrid(7,2).setId('grid');
var list1 = app.createListBox().setName('list1');
for(var i in listitems){list1.addItem(listitems[i])}
var Textbox1 = app.createTextBox().setWidth('150px').setName('TB1');
var schllist = app.createListBox().setName('schllist');
for(var i in schoollist){schllist.addItem(schoollist[i])}
var Textbox2 = app.createTextBox().setWidth('150px').setName('TB2');
var email = app.createTextBox().setWidth('150px').setName('mail');
var upLoad = app.createFileUpload().setName('uploadedFile');
var submitButton = app.createSubmitButton('<B>Submit</B>');
var warning = app.createHTML('Please fill in all fields').setStyleAttribute('background','#bbbbbb').setStyleAttribute('fontSize','20px');
//file upload
var cliHandler2 = app.createClientHandler()
.validateLength(Textbox1, 1, 40).validateNotMatches(list1,'Select a category').validateEmail(email).validateNotMatches(upLoad, 'FileUpload')
.forTargets(submitButton).setEnabled(true)
.forTargets(warning).setHTML('Now you can submit your form').setStyleAttribute('background','#99FF99').setStyleAttribute('fontSize','12px');
//Grid layout of items on form
grid.setWidget(0, 1, title)
.setText(1, 0, 'Category')
.setWidget(1, 1, list1.addClickHandler(cliHandler2))
.setText(2, 0, 'School')
.setWidget(2, 1, schllist.addClickHandler(cliHandler2))
.setText(3, 0, 'Name')
.setWidget(3, 1, Textbox1.addClickHandler(cliHandler2))
.setText(4, 0, 'Email')
.setWidget(4, 1, email)
.setText(5, 0, 'File Upload')
.setWidget(5, 1, upLoad.addChangeHandler(cliHandler2))
.setWidget(6, 0, submitButton)
.setWidget(6, 1, warning);
var cliHandler = app.createClientHandler().forTargets(warning).setHTML('<B>PLEASE WAIT WHILE THE FILE IS UPLOADING<B>').setStyleAttribute('background','yellow');
submitButton.addClickHandler(cliHandler).setEnabled(false);
panel.add(grid);
app.add(panel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
var ListVal = e.parameter.list1;
var SchoolVal=e.parameter.schllist;
var textVal = e.parameter.TB1;
var Email = e.parameter.mail;
var fileBlob = e.parameter.uploadedFile;
var img = DocsList.createFile(fileBlob);
try{
var folder = DocsList.getFolder('Illuminations 14 Submissions/Art');
}catch(e){DocsList.createFolder('Illuminations 14 Submissions/Art');var folder = DocsList.getFolder('Illuminations 14 Submissions/Art/')}
//var schoolFolder = folder.createFolder(SchoolVal)
img.addToFolder(folder);
img.removeFromFolder(DocsList.getRootFolder())
var sheet = SpreadsheetApp.openById(submissionSSKey).getSheetByName('Art');
var lastRow = sheet.getLastRow();
// var image = sheet.insertImage(img.getUrl(), 4, lastRow+1)
var targetRange = sheet.getRange(lastRow+1, 1, 1, 5).setValues([[SchoolVal,ListVal,textVal,Email,img.getUrl()]]);
//var GDoc = DocumentApp.openByUrl(docurl)
//GDoc.appendTable([['Category : '+ListVal,'Name : '+textVal,'Email : '+Email]])
//var par = GDoc.appendParagraph('IMAGE PREVIEW')
//par.insertInlineImage(1, img.getThumbnail())
//GDoc.appendHorizontalRule();
//GDoc.saveAndClose();
app.add(app.createLabel('Thank you for submitting'));
return app
}
My questions is in function doPost(e), How are the variable declarations able to get values from functio doGet() with a declaration like var ListVal = e.parameter.list1;? Is it the e.parameter? I'm not sure how the e.parameter works. I've got other questions with folder creation, but this is the first step. Thanks in advance for your time.
Radley