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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:06:28+00:00 2026-06-10T06:06:28+00:00

I am using the form validation library however I have come across something I

  • 0

I am using the form validation library however I have come across something I cannot work out how to do.

I have several fields,

I have:

  • page_title => required
  • menu_title => not required
  • parent_id => null or required

Now if menu_title is not set then it should take on the value of page_title.
Then, I need to do a check to make sure that, at the given level the menu_title is unique.

So,

if($menu_title == '')
    $menu_title = $page_title;

return $this->db->
select('menu_title')->
from('cart_categories')->
where(array('menu_title' => $menu_title,
            'parent_id' => $category_parent))->
get()->num_rows() == 0;

But I don’t know how to actually use that in the form validation library?

  • 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-10T06:06:30+00:00Added an answer on June 10, 2026 at 6:06 am

    You’ll need to use a callback function in order to do that. Just define one (changed code around slightly to fit formatting). Note, this is off the top of my head (and the docs):

    public function check_title($string) {
        $this->db->select('menu_title')->from('cart_categories');
        $this->db->where(array('menu_title' => $string,'parent_id' => $this->input->post('category_parent')));
        if ($this->db->get()->num_rows() != 0 {
            $this->form_validation->set_message('check_title', '%s must be unique');
            return FALSE;
        }
        return TRUE;
    }
    

    Then set the input for that particular field to use the callback:

    $this->form_validation->set_rules('menu_title', 'Menu Title', 'callback_check_title');
    

    I think you can add an additional underscore to the left side of the callback function name to make sure CI does not route it (as it is public), and just reflect that where you enter the callback name to the rules. I’m not positive about that, though.

    As far as passing the additional field as the callback only takes the string, you could just set a class variable.

    You can also just handle the validation yourself, which might be cleaner in your case.

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

Sidebar

Related Questions

I have made a form validation using ajax post method. But i got the
I am using jquery validation plugin for form validation. I have added a custom
I have a form that is using scriptaculous form validation but i am using
I'm using JSF 2.0 and PrimeFaces library. I have a page with several inputs
I am using the Webshims library for polyfilling the validation of a HTML5 form.
I have the form_validation library loaded in my controller and the form validation itself
i have a html form with 3 fields dateFrom and dateto and iam using
I have some script for image upload and I'm using it with form validation.
I'm creating a registration form using validation inside the User model such as validates_confirmation_of
Client side form validation becomes easiest by using jQuery. I tried all validators and

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.