I have a codeigniter controller with the following check() function to check username and password.
http://localhost/prakash/modules/index.php/login/login/login/login/login/login/check
and every time I submit the form (from the view), the above link is generated. How can I overcome it. I could have used redirect('login') in the controller instead of $this->load->view('login/login_form'); but in that way it wouldnt display the validation errors in the form.
My Controller is
function check(){
$this->form_validation->set_rules('username', 'Username', 'required');
if($this->form_validation->run()==FALSE){
$this->load->view('login/login_form');
}else{
$this->load->model('loginModel');
$query = $this->loginModel->validate();
if($query){
$data = array('username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
//redirecting to appropriate page
redirect('success');
}else{
$this->session->set_flashdata('loginCheck','Username/Password Comination Incorrect!');
redirect('login');
}
}
}
My view is
<section class="main">
<form class="form-1" action="login/check" method="post">
<?php echo "<p class=\"text-error\">{$this->session->flashdata('loginCheck')}</p>"; ?>
<?php echo validation_errors(); ?>
<p class="field">
<input type="text" name="username" placeholder="Username or email">
<i class="icon-user icon-large"></i>
</p>
<p class="field">
<input type="password" name="password" placeholder="Password">
<i class="icon-lock icon-large"></i>
</p>
<p class="submit">
<button type="submit" name="submit"><i class="icon-arrow-right icon-large"></i></button>
</p>
</form>
</section>
The problem is with the action attribute of the form tag
Change
To
Or better (if you are using the url helper)
Why is it happening?
You are using a value that is relative to the
pathof the current url.HTML form action Attribute
Example 1
http://www.example.com/<form class="form-1" action="login/check" method="post">http://www.example.com/login/checkExample 2
http://www.example.com/login/<form class="form-1" action="login/check" method="post">http://www.example.com/login/login/checkExample 3
http://www.example.com/login<form class="form-1" action="/" method="post">http://www.example.com/