PDA

View Full Version : Server validation



stevev
3 Sep 2010, 9:49 AM
Hi all

I'm trying to perform server side validation before a logon form is submitted to the server.

I have the following code:


function fn_login() {
Ext.Ajax.request({
url: 'index.php/login/validate',
method: 'POST',
params: {
username: Ext.getCmp('username').getValue(),
password: Ext.getCmp('password').getValue()
},
success: function() {
fn_authenticate();
},
failure: function(responce) {
login_form.getForm().reset();
Ext.Msg.alert(responce.msg);
}
});
}
My PHP script return the correct value but the Ext code does not work, if the PHP code return false the authenticate function is called. The form.getForm().submit() function is called in fn_authenticate.

Could someone please help?

Thanks

3 Sep 2010, 10:59 AM
Approved your moderated thread.

Ext.Ajax.request's success handler will *ALWAYS* Be called when the server returns a favorable HTTP status code (200/300's).

stevev
3 Sep 2010, 10:35 PM
Thanks for replying

Ok, so how sould I do server side validation before submitting the form. If validation fails the form submission sould not take place.

Condor
6 Sep 2010, 2:37 AM
You don't want to do 2 requests. Instead, have your server return the submission status (OK or error) and check this status in the success handler.

stevev
7 Sep 2010, 6:52 AM
Thanks Condor

That is what I did.