PDA

View Full Version : inserting data to db via form



lormitto
6 Feb 2010, 8:04 AM
hi,

I am trying to figure out for few hours where my mistake is.




I've got a for with multiple textfields that should be sent to server, executed and inserted to db.

However I've got warning that data is not sent. While executing server side file itself on remote server everything works. Problem I've got in my opinion is combined somehow with form but I can not say what is wrong. Please if you could look at code and advise something:


Part of the form



var simpleForm2 = new Ext.FormPanel({
title: '',
url: 'save.php',
bodyStyle: 'padding:5px',
width: 850,
labelWidth: 180,
frame: true,
items: {
layout: 'column',
border: false,
defaults: {border: false},
items: [{
columnWidth: 0.45,
items: [{
layout: 'form',
border:false,
defaultType: 'textfield',
items: [


{
fieldLabel: 'comment',
name: 'comment',
id: 'comment',
allowBlank:false
}

...




Buttons:


buttons: [{
text: 'Save',
handler: function () {

simpleForm2.getForm().submit({
waitMsg: 'saving',
success: function () {
Ext.MessageBox.alert ('it is done');

simpleForm2.getForm().reset();
},
failure: function () {
Ext.MessageBox.alert ('failure');
}
});
}
},{
text: 'Cancel',
handler: function () {

simpleForm2.getForm().reset();
}
}]I got "failure" message box

I tried to place: method: 'POST' and params: {action: 'insert'}. It seems that this is not a problem as well.


Thank you for any help in advance.

cerad
6 Feb 2010, 8:27 AM
What does firebug show for the request/responses?

lormitto
6 Feb 2010, 8:36 AM
What does firebug show for the request/responses?

i do not know because under ubuntu i've got information that console is turned off.
I went through options but could not turn it on

probably that's the moment i should switch back to windows :)

cerad
6 Feb 2010, 8:50 AM
i do not know because under ubuntu i've got information that console is turned off.
I went through options but could not turn it on

probably that's the moment i should switch back to windows :)
Not unless you want to. Press F12 to start firebug. Make sure you have the latest versions. No reason it should not work under ubuntu that I know of.

Debugging AJAX without something like firebug can be very challenging.

lormitto
6 Feb 2010, 8:52 AM
my fault

i am blind or something

it is working now

however it does not show anything in console


and no idea what else I can do to verify where ther problem is

lormitto
6 Feb 2010, 8:59 AM
i have another approach:




buttons: [{
text: 'Save',
handler: function () {


// waitMsg: 'saving...',
var conn = new Ext.data.Connection();
conn.request({
url: 'add.php',
params: {action: 'insert'
},
success: function () {
Ext.MessageBox.alert ('saved');

simpleForm2.getForm().reset();
},
failure: function () {
Ext.MessageBox.alert ('failure');
}


});}
},{
text: 'Cancel',
handler: function () {

simpleForm2.getForm().reset();
}
}]



This one gave saved but variable was not sent. I will check it with console but this approach seems to be more complicated and difficult

cerad
6 Feb 2010, 9:03 AM
I don't see anything obviously wrong with what you posted.
Make a simple form with just a regular text field and make sure it posts ok. Then add to it. It's strange that the failure handler is being called but no request is being made. Does the firebug NET tab show anything?

lormitto
6 Feb 2010, 9:04 AM
when i change in second approach


params: {action: 'insert',
comment: comment

},

firebug says that comment is not defined

probably it's a matter of scope but how to resolve it in this case?

lormitto
6 Feb 2010, 9:07 AM
I don't see anything obviously wrong with what you posted.
Make a simple form with just a regular text field and make sure it posts ok. Then add to it. It's strange that the failure handler is being called but no request is being made. Does the firebug NET tab show anything?


yes it shows planty of GETs

lormitto
6 Feb 2010, 9:11 AM
when i change in second approach


params: {action: 'insert',
comment: comment

},firebug says that comment is not defined

probably it's a matter of scope but how to resolve it in this case?

what is funny when i place
comment: 'some text' -> some text is sent



If I knew how to resolve that, second approach would be good enough - just to run appliaction :)