PDA

View Full Version : [newbie] FormPanel submit format



rmanchu
9 Aug 2009, 2:51 AM
I'm new and treading the waters with ExtJS - please bear with me :)

When I do a FormPanel submit - what is the format of the submission? is it JSON where all the fields in the FormPanel are the key/values in that JSON Object. My confusion is because of the following code - available from the ExtJS website - which seem to explicitly insert the required params in the the JSON? object. In fact, all of the fields are explicitly declared as global vars - which seem to be odd to me.



function saveThePresident(oGrid_event){
Ext.Ajax.request({
waitMsg: 'Please wait...',
url: 'database.php',
params: {
task: "UPDATEPRES",
IDpresident: oGrid_event.record.data.IDpresident,
FirstName: oGrid_event.record.data.FirstName,
LastName: oGrid_event.record.data.LastName,
PartyName: oGrid_event.record.data.PartyName,
TookOffice: oGrid_event.record.data.TookOffice.format('Y-m-d'),
LeftOffice: oGrid_event.record.data.LeftOffice.format('Y-m-d'),
Income: oGrid_event.record.data.Income
},
success: function(response){
var result=eval(response.responseText);
switch(result){
case 1:
PresidentsDataStore.commitChanges();
PresidentsDataStore.reload();
break;
default:
Ext.MessageBox.alert('Uh uh...','We couldn\'t save him...');
break;
}
},
failure: function(response){
var result=response.responseText;
Ext.MessageBox.alert('error','could not connect to the database. retry later');
}
});
}

Animal
9 Aug 2009, 3:30 AM
It's submitted in perfectly normal HTTP form submission format.

The response must be JSON as described i nthe API docs.

Animal
9 Aug 2009, 3:31 AM
errrr, what global variables?

That's code that's doing a "manual" submission of a Record from a Store using Ajax directly.

To submit a form just use the submit method of the form.

rmanchu
9 Aug 2009, 3:52 AM
FormField names and their values are submitted which we can get using standard getParameter methods? But do we have to explicitly set the parameters as in the OP code? Or all fields contained within the FormPanel be submitted on a formPanel.submit()?

The global vars part in not in the OP code. Sorry.

Animal
9 Aug 2009, 3:54 AM
Try it!

Docs with example code: http://extjs.com/deploy/dev/docs/?class=Ext.form.BasicForm&member=submit