PDA

View Full Version : Login Form with PHP. How to proceed?



ibagur
3 Jun 2011, 8:54 PM
Hi all,

I know that this sounds very simple, but I have not managed to make it work. Basically I got a simple Ext Js login form. The form submit to my login.php, which performs a database check and if the user exist, then issues a 'success:true' JSON string back to Ext JS.

Now the question, how do I redirect then the user to my other script 'home.php'? I have tried to put a redirection just after the 'echo '{success:true}' but it does not seem to work. Also I tried to make an ajax request from the Ext Js, but it doesn't work either...I cannot get through the TRUE/FALSE json thing! How can I make it work? I just want to call another script when the login validation is successful.

Here is a sample of my extjs login request:

buttons: [{
text: 'Login',
handler: function(){
if(loginForm.getForm().isValid()){
loginForm.getForm().submit({
waitMsg: 'Processing Request',
success: function(f,a){
msg('Success', a.result.msg);
}
});
}
}
}]

And the login.php has a method called 'submit' that is the one being called by the login form. I post here a very simplified version, as I do a database validation. Also I use sessions to prevent non authenticated users to access any other script:

public function submit() {
// set the logged COOKIE to True
$this->session->set_userdata('logged', TRUE);
echo '{success:true, msg:'.json_encode("Welcome").'}';
redirect('home.php');
}

I am using CodeIgniter on the php side, but in anycase, if I use 'header()' instead of 'redirect()', it does not work either. I get the ExtJs waiting message stuck in a neverending loop.

Sorry for not using the code format tags, it's not working from Chrome (I do not why).

httpdotcom
3 Jun 2011, 10:05 PM
You can't use the PHP page to redirect, but you could pass the URL from it.

from extjs form


...
,success: function(f,a) {
document.location = a.result.url ;
}
...

ibagur
4 Jun 2011, 7:24 AM
Hi, thanks alot! It's working now ;)