PDA

View Full Version : Display Message in Event Handler



haden
13 May 2011, 9:22 AM
I'd like to display a message passed back from my server, someplace on my form. To start, I'd just like to 'alert' the message. I can see the json in Firebug's console/response - but msg is undefined.

Is my problem the json format, an incorrect reference to msg in the handler, or something else?
Thanks.

on the server:

if ($rs == 1)
echo '{"success": true, msg: "Thank you for your submission."}';
else
echo '{success: false}';

client:

buttons: [{
text: 'Save',
handler: function(){
Order.getForm().submit({
success: function(form, action, msg){
Ext.Msg.alert(msg);

},
failure: function(form, action){...

friend
13 May 2011, 9:53 AM
I don't see a url attribute in your form submit, but I'll assume that's a cut/paste error.

The success handler only accepts a form and action parameter, where you need to retrieve any messages from the action object. Note that the action object is implicitly decoded as JSON, so you can access its properties directly:



<...>
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
}
<...>

haden
13 May 2011, 12:41 PM
That worked!

After looking at your answer, I again tried to see if I could find the answer in the docs myself and came to the submit method of Basicform, which if you click on the arrow, has a nice usage example. I've been missing these by clicking on the topic and going to the source code - which for me at this point - is a bit impenetrable.

Anyway, thanks so much friend.