I need to display an error message for a custom validation rule, but I can't get to do it.
This is the validation rule:
$config = array(
....,
array(
'field' => 'general_sales_subaccount',
'label' => 'General Sales Subaccount',
'rules' => array(
'required',
'numeric',
array(
$this->subaccounts_model,
'is_valid'
)
),
)
);
$this->form_validation->set_rules($config);
And now this is the referenced model method:
public function is_valid($subaccount)
{
$subaccount_num_digits = $this->preferences->get('subaccount_num_digits');
if (strlen($subaccount) != $subaccount_num_digits ) {
$this->form_validation->set_message('is_valid', "The number of digits in %s doesn't match the length set to " . $subaccount_num_digits);
return false;
}
return true;
}
The rule seems to work, but it displays this error message:
Unable to access an error message corresponding to your field name (Anonymous function).
Any ideas?