Hi devbro! Thanks for a great library. I have a question about setting rules. The rules are shown as below.
'rules' => 'file_allowed_type[image]|file_size_max[1800KB]'
Notice that I didn’t set the file_required in my rule.
When no file is selected, without file_required, the validation message still shows up. Is this the expected behaviour? Or, there is another way to make the file is an optional field, but if one is selected, still validates the type and size?
UPDATE
I find the follow comments in the code.
// If the field is blank, but NOT required, no further tests are necessary
The code followed after the comments seems missing a return statement so it will break out the function with no further processes. Therefore, I add the following code.
The whole block of code is shown below.
// If the field is blank, but NOT required, no further tests are necessary
$callback = FALSE;
if ( ! in_array('file_required', $rules) AND $postdata['size']==0)
{
// Before we bail out, does the rule contain a callback?
if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match))
{
$callback = TRUE;
$rules = (array('1' => $match[1]));
}
else
{
return;
}
}
The changes seem work for me. If someone uses this, please double test it. If the changes breaks the validation, please let me. I need to change it back.