Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Validation: notEmpty vs. notBlank #6752
I'm a bit confused about the usage of
(1) Not possible to set the error message. You always get the default one.
(2) Possible to set a custom error message.
Since 3.0.2 it's recommended to use
(1) Also not possible to set a custom error message.
Both ways (
There is an issue about consistency at the validation rules, so I will reference it here but is not really related. Refs: #6444
So if want to ensure a field is not empty use
$validator->notEmpty('username', 'custom mesage');
and if you want to ensure a field is not empty and also does not contain only whitespace use
$validator ->add('username', [ 'notBlank' => [ 'rule' => 'notBlank', 'message' => 'My custom message.' ]);
Thanks for your quick response. I understand the difference between them now. They are two different things and that was probably the reason for renaming. So in general I could use both togehter?