Welcome Guest, Not a member yet? Register   Sign In
Redirect Best Practice
#1

[eluser]MercuryLime[/eluser]
I recently started using CI and I love it.

I am building a web app and I planned to have all of the complex stuff in one 'processes' controller. I would submit forms to it and have it redirect to the appropriate page after going through logic. However, I haven't been able to get validation to work.

Form code (in a view loaded by 'home' controller):
Code:
<font style="color: #f00;">&lt;?php echo $this->validation->error_string; ?&gt;</font>

&lt;?php
echo form_open('process/login');
echo 'User:' . form_input('username') . '<br />';
echo 'Pass:' . form_password('password') . '<br />';
echo form_submit('submit', 'Enter!');
echo form_close();
?&gt;

Process code (in 'processes' controller):
Code:
function Login()
{
    $rules['username'] = "required";
    $rules['password'] = "required";
    $this->validation->set_rules($rules);
    if ($this->validation->run() == FALSE)
    {
        // Return to main page, display errors
    }
    else
    {
        // Try to log in
        $query = $this->db->get_where('users', array('username' => $this->input->post('username'), 'password' => $this->input->post('password')));
        if ($query->num_rows() > 0)
        { $this->session->set_userdata(array('username'=>$this->input->post('username'), 'password' => $this->input->post('password')));
        }
        else {
        }
    }
    redirect('');
}

If I submit the form it gets sent to the process and redirected back without showing any errors.

My questions are:
1) What is the best practice for redirects? Should I try to avoid them whenever possible (does it create multiple instances of CI and take up processing power?)
2) Any suggestions for why this code isn't working? I'm pretty sure it has something to do with the redirects.


Messages In This Thread
Redirect Best Practice - by El Forum - 06-05-2008, 11:19 PM
Redirect Best Practice - by El Forum - 06-05-2008, 11:32 PM
Redirect Best Practice - by El Forum - 06-05-2008, 11:53 PM
Redirect Best Practice - by El Forum - 06-06-2008, 01:12 AM
Redirect Best Practice - by El Forum - 07-09-2008, 11:12 AM
Redirect Best Practice - by El Forum - 08-15-2010, 12:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB