PDA

View Full Version : Form submit success/failure problem



ext4phil
20 Sep 2007, 1:54 AM
Hello to you all,

I have writen the below code as I am trying to understand how the success/failure callback functions get called

when my PHP returns {success:true} the success callback runs as expected
when my PHP returns {success:false} then I get stuck with the waitMsg: 'Testing, please wait...'

what must I do to have the failure callback run.

HTML Code


<html>
<head>
<script src="yui-utilities.js" type="text/javascript"></script>
<script src="ext-yui-adapter.js" type="text/javascript"></script>
<script src="ext-all-debug.js" type="text/javascript"></script>
<script src="FormTest01.js" type="text/javascript"></script>
<link href="./css/ext-all.css" media="screen" rel="Stylesheet" type="text/css" />
</head>
<body>
<div id="myForm"></div>
</body>
</html>


JS Code


Ext.onReady(function(){
var simple = new Ext.form.Form();
simple.addButton(
{
text: 'Test',
handler: function() {
simple.submit(
{
waitMsg: 'Testing, please wait...',
url:'./FormTest01.php',
params:{param01:"01", param02:"02"},
success:function(form, action) {
alert('Congrats! success!');
},
failure: function(form, action) {
alert('Oops failure!');
}
}
);
}
}
);
simple.render('myForm');
});


PHP Code


<?php echo("{success:true}"); ?>

Animal
20 Sep 2007, 1:58 AM
YOu must have a data:{} property, otherwise, the Action calls the failure callback.

ext4phil
20 Sep 2007, 6:39 AM
Dear Animal,

My problem is that I can NOT get into the failure callback.

With the simple {success:true} I can get into success callback even without a data:{} property.

Animal
20 Sep 2007, 6:41 AM
The failure callback is only called if the HTTP communicatin fails.

Animal
20 Sep 2007, 6:42 AM
Ah yeah, submit does not require data:{}. load does. Oops!

ext4phil
20 Sep 2007, 7:27 AM
I see ... "only called if the HTTP communicatin fails" ...

In that case it would not make sence to use {success:false}, I guess it's ignored.

I was trying to use it when I would find errors in my php.

Thanks Animal

Animal
20 Sep 2007, 7:39 AM
I'm just checking the code. Actually, the failure callback gets called on success:false.

Animal
20 Sep 2007, 7:41 AM
It's just that the Action's failureType property will be set to Ext.form.Action.CONNECT_FAILURE if it was an HTTP error.

The failureTypes are



Ext.form.Action.CLIENT_INVALID = 'client';
/**
* Failure type returned when server side validation of the Form fails
* indicating that field-specific error messages have been returned in the
* response's <pre>errors</pre> property.
* @type {String}
*/
Ext.form.Action.SERVER_INVALID = 'server';
/**
* Failure type returned when a communication error happens when attempting
* to send a request to the remote server.
* @type {String}
*/
Ext.form.Action.CONNECT_FAILURE = 'connect';
/**
* Failure type returned when no field values are returned in the respons's
* <pre>data</pre> property.
* @type {String}
*/
Ext.form.Action.LOAD_FAILURE

ext4phil
20 Sep 2007, 9:24 AM
Dear Animal,

I located the source of my problem.

I was watching the "Editable Grid Component" screencast
http://extjs.com/learn/Screencast:Editable_Grid_Component

and I downloaded the source files
http://extjs.com/downloads/editgridoverview/ext-editgriddemo.zip

I started working with this code and it included an older ext-all-debug.js in the zip (ver 1.0)
I just realized this and I included in my HTML ext-all-debug.js ver 1.1.1

Now {success:false} works as expected .... I promise I will be more carefull next time.

Started using ExtJS on Monday and I am ecstatic ... or shall I say EXT-atic.
You guys just got one more fan in you club. Where can I order my T-Shirt :)

Thanks for your time ... and sorry for the trouble.

Animal
20 Sep 2007, 11:55 AM
Yes, there should be a tee shirt.

Jack, Brian? Are you selling tee shirts yet?