定义form:
form = new Ext.FormPanel({
labelWidth: 80, // label settings here cascade unless overridden
url:'test.php',
frame:true,
title: 'Add a New Partner Profile',
bodyStyle:'padding:5px 5px 0',
width: 300,
defaults: {width: 150},
defaultType: 'textfield',
items: [{
fieldLabel: 'ID',
name: 'id'
},{
fieldLabel: 'Name',
name: 'name',
allowBlank:false
},new Ext.form.NumberField({
fieldLabel: 'Priority',
name:"priority",
allowBlank : false
})],
buttons: [{
text: 'Save',
handler:function(){
if(form.getForm().isValid())
{
form.getForm().submit({
waitMsg:'Submitting.....',
success: function(form, action){
},
failure:function(form, action){
obj = Ext.util.JSON.decode(action.response.responseText);
Ext.Msg.alert('Message', obj.errors.reason);
}
});
}else{
Ext.MessageBox.alert("Message","!");
}}
},{
text: 'Cancel'
}]
});
form.render("showdiv");
test.php页面用json返回数据,格式为:
{"success":true,"errors":{"reason":"some reason"}}