[eluser]CroNiX[/eluser]
You can set the error message, and retrieve it. See the "callbacks" section of the form validation library in the user guide.
Code:
function valid_array_element($str, $allowed)
{
$allowed = explode(';', $allowed);
if (in_array($str, $allowed))
{
return TRUE; //return TRUE, passed the rule
}
else
{
//failed rule, set error message and return FALSE
$this->form_validation->set_error('valid_array_element', 'The %s field can only be one of the following options: ' . implode(', ', $allowed));
return FALSE;
}
}
Then in your form, where this form element is, you'd show the individual error like any other validation error.
Code:
echo form_error('name-of-field-this-rule-was-applied-on');
Which would show "The Somefield field can only be one of the following options: a, aa, aaa", if it failed.