PDA

View Full Version : handling xml response on form submit



satishp
1 Dec 2009, 5:37 AM
Hi,

When I submit form I get response in xml format. I get proper response. But it gives error

unterminated regular expression literal
apply()()ext-base.js (line 7)
apply()()ext-base.js (line 7)
apply()()ext-base.js (line 7)
o()ext-base.js (line 7)
apply()()ext-base.js (line 7)

(<?xml version='1.0' encoding='UTF-8'?><...lt><Status>Successful</Status></Result>)

My code is like


var fs = new Ext.FormPanel({
frame: true,
title:'XML Form',
id:'plan-panel1',
labelAlign: 'right',
labelWidth: 85,
width:340,
waitMsgTarget: true,
// configure how to read the XML Data
reader : new Ext.data.XmlReader({
record : 'contact',
success: '@success'
}, [
{name: 'first', mapping:'name/first'}, // custom mapping
{name: 'last', mapping:'name/last'},
'company', 'email', 'state',
{name: 'dob', type:'date', dateFormat:'m/d/Y'} // custom data types
]),
items: [
new Ext.form.FieldSet({
title: 'Contact Information',
autoHeight: true,
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
width:190
}, {
fieldLabel: 'Last Name',
name: 'last',
width:190
}, {
fieldLabel: 'Company',
name: 'company',
width:190
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email',
width:190
},
new Ext.form.DateField({
fieldLabel: 'Date of Birth',
name: 'dob',
width:190,
allowBlank:false
})
],
buttons: [{
text: 'Save',
handler: function(){
submitSF();
}
},{
text: 'Cancel'
}]
})
]
});
simple.render(document.body);
fs.render(document.body);

function submitSF()
{

var newPlanForm = Ext.getCmp('plan-panel1').getForm();
newPlanForm.submit({
//method: "POST",
url:"test.php (http://www.extjs.com/forum/"test.php)",
reader: new Ext.data.XmlReader({
success: "@Status"
}),
// configure how to read the XML Data
success: function(form, action) {
alert("SUCCESS");
//alert("SUCCESS: "+action.response.responseXML);
// on success do
},
failure: function(form, action) {
alert("FAILED");
// on failure do
//alert("FAILURE: "+action.response.responseXML);
}
});
}


Thanks in advance.......
satishP

Condor
4 Dec 2009, 2:35 AM
You can't specify a reader in the submit() method parameter.

You'll need to specify the reader as the 'errorReader' in the form config object.

satishp
4 Dec 2009, 4:32 AM
'errorReader' solved my problem.
Thank you very much Condor.

joearul
4 Dec 2009, 11:59 AM
Sathish,

Can you post ur modified code?

J

satishp
4 Dec 2009, 11:21 PM
Form code



Ext.onReady(function () {
var fs = new Ext.FormPanel({
frame: true,
title: 'XML Form',
id: 'plan-panel1',
labelAlign: 'right',
labelWidth: 85,
width: 340,
items: [
new Ext.form.FieldSet({
title: 'Contact Information',
autoHeight: true,
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
width: 190
},
{
fieldLabel: 'Last Name',
name: 'last',
width: 190
}],
buttons: [{
text: 'Save',
handler: function () {
submitSF();
}
},
{
text: 'Cancel',
handler: function () {}
}]
})]
});
fs.render(document.body);

function submitSF() {
var newPlanForm = Ext.getCmp('plan-panel1').getForm();
newPlanForm.errorReader = new Ext.data.XmlReader({
record: 'Result',
success: 'Status'
},
['Status']);
newPlanForm.submit({
//method: "POST",
url: "text.xml",
success: function (form1, action1) {
alert("SUCCESS");
},
failure: function (form1, action1) {
alert("FAILED");
}
});
}
});


return xml



<?xml version='1.0'?>
<Result>
<Status>true</Status>
</Result>


SatshP
:):):)

satishp
4 Dec 2009, 11:24 PM
Form Code



Ext.onReady(function () {
var fs = new Ext.FormPanel({
frame: true,
title: 'XML Form',
id: 'plan-panel1',
labelAlign: 'right',
labelWidth: 85,
width: 340,
items: [
new Ext.form.FieldSet({
title: 'Contact Information',
autoHeight: true,
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
width: 190
},
{
fieldLabel: 'Last Name',
name: 'last',
width: 190
}],
buttons: [{
text: 'Save',
handler: function () {
submitSF();
}
},
{
text: 'Cancel',
handler: function () {}
}]
})]
});
fs.render(document.body);

function submitSF() {
var newPlanForm = Ext.getCmp('plan-panel1').getForm();
newPlanForm.errorReader = new Ext.data.XmlReader({
record: 'Result',
success: 'Status'
},
['Status']);
newPlanForm.submit({
//method: "POST",
url: "text.xml",
success: function (form1, action1) {
alert("SUCCESS");
},
failure: function (form1, action1) {
alert("FAILED");
}
});
}
});


Return Xml



<?xml version='1.0'?>
<Result>
<Status>true</Status>
</Result>



SatishP,
:):):)

joearul
7 Dec 2009, 1:53 PM
Thanks Sathish

J