Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:47:00+00:00 2026-06-13T23:47:00+00:00

I have a login form that is using CI form validation. The form is

  • 0

I have a login form that is using CI form validation.

The form is at domain.com/login

It runs a function called validate_credentials and if the validation fails it reloads the view. The problem is the URL continues to show:

domain.com/login/validate_credentials

How can I remove the /validate_credentials?

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

    public function index()
    {
    $this->load->library('form_validation');

    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
    $this->form_validation->set_rules('password', 'Password', 'required');

    $this->form_validation->set_error_delimiters('<div class="alert alert-error">', '</div><br />');

    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('login/login');
    }
    else
    {
        $this->load->view('clock/clock');
    }

}

function validate_credentials() {
    $this->load->model('membership_model');
    $query = $this->membership_model->validate();

    if($query) {// staff credentials validated...
        $data = array(
                'email' => $this->input->post('email'),
                'staff_logged_in' => TRUE
            );

            $this->session->set_userdata($data);
            redirect('clock/clock');
    }

    else {  // not validated reload index function
        $this->index();
    }
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:47:02+00:00Added an answer on June 13, 2026 at 11:47 pm

    Instead of calling the other controller function, do a redirection to the index. Because functions in controllers in CodeIgniter are setting the URL scheme, the way you do it right now is just executing the index function, but within the validate_credentials function (and URL).

    Do like this:

        <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Login extends CI_Controller {
    
        public function index()
        {
        $this->load->library('form_validation');
    
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'required');
    
        $this->form_validation->set_error_delimiters('<div class="alert alert-error">', '</div><br />');
    
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('login/login');
        }
        else
        {
            $this->load->view('clock/clock');
        }
    
    }
    
    function validate_credentials() {
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();
    
        if($query) {// staff credentials validated...
            $data = array(
                    'email' => $this->input->post('email'),
                    'staff_logged_in' => TRUE
                );
    
                $this->session->set_userdata($data);
                redirect('clock/clock');
        }
    
        else {  // not validated reload index function
            //$this->index();
            $this->load->helper('url'); //to enable redirect function
            redirect('index'); //based on your index url
        }
    }
    
    }
    

    If you need to display a error or success message, please refer to flash_message of the session library of CodeIgniter, but here is an example.

    Set the error message in your controller, juste before redirecting to the index:

    $this->load->library('session');
    $this->session->set_flashdata('error_message', "This is my error message");
    

    And in your index view, you display it if it exists:

    <?if($this->session->flashdata('error_message')):?>
        <div class="nNote nFailure"><p><?=$this->session->flashdata('error_message');?></p></div>
    <?endif;?>
    

    Please note that a flash_message is shown once. Which means your index will show your error and then destroy the session message. This is the purpose of flash_message, to correctly and simply show error messages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function in my login form that checks if the email and
I'm using asp.net mvc 3 with unobtrusive jquery validation. I have a form that
I Have done a login form validation using jquery, But Thing is error message
I have a login form that has Username and password as inputs from user
The problem I am encountering is that for my login form I have to
I have a form on my website that does the login. To make the
I have this login form. This form is a grouped table view where the
I have a simple cakephp form WITH validation that submits to a database. It
I have a user input form here: http://www.7bks.com/create (Google login required) When you first
I am using MVC3 and I want to have LogIn form and Register form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.