CodeIgniter has many validation rules but is there any rule for checking if the value from a certain field is present in an array(given as parameter to the validation rule)?
For example:
$possible_values = array('beer', 'soda', 'wine', 'water');
$this->form_validation->set_rules('drink', 'Drink', 'required|trim|found_in_array[possible_values]');
you can use callback_function_name
like so,
$this->form_validation->set_rules('drink', 'Drink', 'callback_customInArray');
public function customInArray($str)
{
$possible_values = array('beer', 'soda', 'wine', 'water');
if(in_array($str, $possible_values){return true;}
return false;
}
read more about that in CI Form Validation