I'm currently working on v3 of the Uniform plugin. This version will be based on the kirby-form plugin which in turn makes use of the invalid helper function to validate the form fields. To this end I'd like to propose some improvements to the invalid function. This PR consists of two idependent commits:
Improved 'required' validation. Now only null, '', [] or undefined variables are rejected by the required validation. Previously '0' was rejected, too.
Improved error messages. Now an array of error messages can be defined for each validation rule, too. Each item of the array corresponds to one validation method so the error messages can be more helpful. Example:
$rules = ['username' => ['required', 'alpha', 'min' => 4]];
$messages = ['username' => [
'The username is required.',
'The username may only contain letters.',
'The username must be at least 4 characters long.',
]];
I've also added a few tests to ensure backwards compatibility. Only the array_unique had to be removed which might result in duplicate error messages in old code.
I'm currently working on v3 of the Uniform plugin. This version will be based on the kirby-form plugin which in turn makes use of the invalid helper function to validate the form fields. To this end I'd like to propose some improvements to the invalid function. This PR consists of two idependent commits:
Improved 'required' validation. Now only
null
,''
,[]
or undefined variables are rejected by the required validation. Previously'0'
was rejected, too.Improved error messages. Now an array of error messages can be defined for each validation rule, too. Each item of the array corresponds to one validation method so the error messages can be more helpful. Example:
I've also added a few tests to ensure backwards compatibility. Only the
array_unique
had to be removed which might result in duplicate error messages in old code.