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

  • SEARCH
  • Home
  • 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 3427180
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:48:19+00:00 2026-05-18T06:48:19+00:00

Im running CodeIgniter for a project of mine … Im fairly new to this,

  • 0

Im running CodeIgniter for a project of mine … Im fairly new to this, i have the standard form validation checks for my form, except im unsure of how to check if the value already exists in the database.

This is what i have for my form validation rules so far

$this->form_validation->set_rules('rolename', 'Role Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('rolekey', 'Role Key', 'trim|required|xss_clean');

The ‘rolekey’ is what i need to check against the ‘rolekey’ column in the database to see if it exists, if it does i need to shoot back an error.

Any help would be grand.

Cheers,

  • 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-05-18T06:48:20+00:00Added an answer on May 18, 2026 at 6:48 am

    There is not a built-in form validation check for whether or not a value is in the database, but you can create your own validation checks.

    In your controller, create a method similar to this:

    function rolekey_exists($key)
    {
        $this->roles_model->role_exists($key);
    }
    

    And in your model that handles roles, add something like this:

    function role_exists($key)
    {
        $this->db->where('rolekey',$key);
        $query = $this->db->get('roles');
        if ($query->num_rows() > 0){
            return true;
        }
        else{
            return false;
        }
    }
    

    And then you can write a form validation check like this:

    $this->form_validation->set_rules('username', 'Username', 'callback_rolekey_exists');
    

    See this page for more information:

    https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods

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

Sidebar

Related Questions

I have enabled the inbuilt logging within Codeigniter. This works fine. However I'm running
I'm running CodeIgniter 2.0 and I have a test controller setup with this code
I have json object like this, the site is running codeigniter which is ultimately
I have a copy of codeigniter running. And I am now also attempting to
I'm working on upgrading a Codeigniter app I have running on 1.7.2 to 2.0.3
I have a CodeIgniter project, and I want to invoke one of my controller
I currently have a CodeIgniter web app running on Ubuntu with nginx. I just
I have a system running in PHP and am using CodeIgniter (if there is
I am running CI version 2.1 and I have recently installed the CodeIgniter 2.1
I have a contest running, and to look at the results I've made this

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.