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,
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:
And in your model that handles roles, add something like this:
And then you can write a form validation check like this:
See this page for more information:
https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods