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 8340515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:11:59+00:00 2026-06-09T05:11:59+00:00

Say I have a login form in CodeIgniter — I can set validation rules

  • 0

Say I have a login form in CodeIgniter — I can set validation rules for individual inputs, but is there a way to throw a model/controller level error and a message?

Specifically, if the below method does not return TRUE, I want my form to re-display with the message “The email address or password is incorrect”. Currently the controller just reloads the view and the set_value()s

public function authorize_user()
{
    $this->db->where('email', $this->input->post('email'));
    $this->db->where('password', $this->input->post('password'));

    $q = $this->db->get('users');

    if($q->num_rows() == 1){
        return true;
    }
}

Perhaps I’m overthinking this and I should just attach that error message to the email input?

  • 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-09T05:12:00+00:00Added an answer on June 9, 2026 at 5:12 am

    You can use a callback function to accomplish this. The steps are as follow:
    1. Your authorize_user() function must be in the controller you set the rules.
    2. You make a “callback” rule by adding a code similar to:

    $this->form_validation->set_rules('email', 'email', 'callback_authorize_user['.$this->input->post("password").']');
    

    Note that I added a parameter for the callback function. These kind of functions automatically receive a parameter which is determined by the first argument of set_rules(). In this case, the argument passed automatically to the callback function is the email. Aditionally, I pass the password as second parameter.

    3.Add the respective parameters to your function:

    public function authorize_user($email,$password)
    {
       //As I said before, the email is passed automatically cause you set the rule over the email field.
        $this->db->where('email', $email);
        $this->db->where('password', $password);
    
        $q = $this->db->get('users');
    
        if($q->num_rows() == 1){
            return true;
        }
    }
    

    More info at: http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks

    Hope it helps!

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

Sidebar

Related Questions

Say I have one full-page form, but within the form, there are two or
Let's say I have a SessionsController , which controls user login and logout, but
let's say I have a simple javascript like so: $(document).ready(function(){ if(login == 1) {
I'm just starting to learn AspectJ, and I have use-case for say, User login.
Let's say you have a business logic method that can perform some operation across
So let's say I have a form which is being sent somewhere strange (and
I have a simple login form, username and password. Basically, When a user is
I have a login form (/user). And methods: -authenticate -logout And one view index.html.erb,
Let's say I have a search form and I want to validate the length
I have a database which has form authentication tables for an website [let say

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.