The current Validation class checks to see if a field has the “required” rule. If it doesn’t, meaning the field is optional, then it only skips the field if two other conditions exists:
1 there’s no “callback” rule
2) the field doesn’t exist in $_POST or the field is empty
// Is the field required? If not, if the field is blank we'll move on to the next test
if ( ! in_array('required', $ex, TRUE) AND strpos($rules, 'callback_') === FALSE)
if ( ! isset($_POST[$field]) OR $_POST[$field] == '')
The problem with that logic is that if a callback rule does exist *and* other rules exist that don’t explicitly check if the field exists or is empty, then validation may fail anyways, even though the field is optional.
Take this set of rules, for example:
$rules['email_address'] = 'valid_email|callback_check_email_is_unique';
There’s no “required” rule, so the field is optional. However, because there is a “callback” rule, that means the “valid_email” rule will be executed. If the field was empty, validation would fail as a result. The valid_email() function doesn’t check (and shouldn’t have to check) whether the field is empty. An empty string is not a valid email address.
Because callback functions are custom functions created by the developer, they can explicitly add a check for an empty or missing value. Therefore, it is my conclusion that a check for a “callback” rule doesn’t belong here. They should not be treated any different than other rules, in my opinion.