Welcome Guest, Not a member yet? Register   Sign In
AJAX form not redirecting
#1

[eluser]cmgmyr[/eluser]
Hey all,
I'm new at CI (and to the forum) so sorry for the noobish questions.

The view:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;
[removed][removed]
[removed][removed]
[removed]
function sendForm(container) {
    var url = '&lt;?=base_url()?&gt;admin/home/login';
    var params = Form.serialize(container);
    var ajax = new Ajax.Request(url,{
        method: 'post',
        parameters: params,
        onComplete: showErrors
    });
}
function showErrors(req){
    if(req.responseText == 'OK'){
        location.href='&lt;?=site_url("admin/catalog")?&gt;';
    }else{
        $('error_messages')[removed] = req.responseText;
        new Effect.Appear('error_messages');
    }
}
[removed]
&lt;/head&gt;

&lt;body&gt;
<div id="error_messages" style="display:none;"></div>
&lt;form id="frm_login"&gt;
<p>&lt;input id="email" name="email" type="text" /&gt;&lt;/p>
<p>&lt;input id="password" name="password" type="text" /&gt;&lt;/p>
<p>&lt;input name="submit" type="submit" value="Login!" /&gt;&lt;/p>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

The Controller:
Code:
function login(){
        $email = $this->input->post('email');
        $password = $this->input->post('password');
        $logged_in = $this->doLogin($email, $password);
        
        if($logged_in){
            //echo 'OK';
            //$this->func->pageForward(site_url("admin/catalog"));
            redirect(site_url("admin/catalog"), 'refresh');
        }
    }
    
    function doLogin($user_email, $user_password){    
        if(!$this->val->check_email($user_email)){
            $this->error->setError("Email address is not valid");
        }
        
        if(!$this->val->check_input($user_password)){
            $this->error->setError("Password is not valid");
        }
        
        if(!$this->error->countErrors()){
            //Check the database for correct information
            $sql = "SELECT * FROM admin WHERE email = '".$user_email."' LIMIT 1";
            $query = $this->db->query($sql);
            
            if($query->num_rows() == 0){
                $this->error->setError("Email address not found");
            }else{
                //Check for both email and password
                $row = $query->row();
                $db_password = $row->password;
                
                if(!$this->func->validate_password($user_password, $db_password)){
                    $this->error->setError("Password doesn't match database");
                }else{
                    $id = $row->id;
                    
                    //See if user account is active or not
                    $sql = "SELECT * FROM admin WHERE id = '$id' AND active = '0'";
                    $query = $this->db->query($sql);
                    
                    if($query->num_rows() > 0){
                        $this->error->setError("Your account is disabled, this might be becuase your account is not approved yet or you have violated the TOS.");
                    }
                    
                    if(!$this->error->countErrors()){
                        //Log user in
                        $newdata = array('admin_id' => $id);
                        $this->session->set_userdata($newdata);
                        
                        return true;
                    }
                }
            }
        }
        
        if($this->error->countErrors()){
            $this->error->showErrors();
        }
        
        return false;
    }

As you can probably see in the JS the redirect in the showErrors() does work BUT I would rather do the redirect in the controller. How it is set up now it shows admin/catalog in the "error_messages" div. Any ideas how I can redirect the whole page and not just the div?

Thanks,
-Chris


Messages In This Thread
AJAX form not redirecting - by El Forum - 08-12-2008, 01:20 PM
AJAX form not redirecting - by El Forum - 08-13-2008, 01:00 PM
AJAX form not redirecting - by El Forum - 08-13-2008, 01:43 PM
AJAX form not redirecting - by El Forum - 08-13-2008, 01:46 PM
AJAX form not redirecting - by El Forum - 08-13-2008, 01:49 PM
AJAX form not redirecting - by El Forum - 08-13-2008, 01:53 PM
AJAX form not redirecting - by El Forum - 08-13-2008, 02:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB