[eluser]sentinel[/eluser]
Hi, I'm sure the following problem is quite simple, but just can't seem to figure it out.
In one of my forms, I call several callback functions for validation. Some of my form elements are mandatory, but some are optional (i.e. ensuring input is either null or a numeric value).
In this case, the first check is for a field that is required and must be numeric.
I use the following rule within my rules array:
Code:
array('field' => 'policyLoan', 'label' => 'Policy Loan Amount', 'rules' => 'required|trim|callback_policyLoan_check'),
When I try and submit the form, if the input is left empty, no errors are returned and nothing seems to happen. However, the form is being submitted and a view returned, because I just checked it on the error log.
If I insert text instead of a number, the validation runs OK and flags up the errors. But if the input is left blank, the validation also does not run on that input, but also does not run the validation on the other form inputs.
The callback function code is:
Code:
function policyLoan_check($str) {
if(empty($str) || is_null($str) || !is_numeric($str)) {
$this->form_validation->set_message('policyLoan_check', 'The amount of the policy loan must be entered in numeric format.');
return FALSE;
}
else
{
return TRUE;
}
}
I can't see anything obviously wrong here. Where could I be going wrong ?? I'm baffled.
Thanks
Neil.