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?
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):
Then set the input for that particular field to use the callback:
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.