-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Print errors in array validations #3917
Comments
If you use |
Hello Paul! try to print it that way but a null value is returned, the format of the array returned in session is as follows array (5) {
// ...
["categories.*"] =>
string (80) "The categories.* field must contain a previously existing value in the database."
} It would be quite nice if the ". *" Could be omitted in the name of the keys when dealing with array validations, or how could I get the error message? Cheers! |
Try setting a // validation rules
'categories.*' => ['rules' => 'is_not_unique[categories.id]', 'label' => 'categories'],
// The categories field ... But note that the array key will still be |
It seems that the name of the label is not associated with the name of the error key because I have tried to put a label to the configuration and it keeps returning 'categories.*' => [
'rules' => 'is_not_unique[categories.id]',
'label' => 'categories',
], as I mentioned before if I try to print the error as it returns null |
It seems like a bug related to fact that we're using dot syntax to handle the nested array values. Until we solve this I guess you should be able to use something like this: <?= session('errors')['categories.*'] ?> |
Yes, as I've said earlier, the field name will still be used as the array key. This is because of the following line in CodeIgniter4/system/Validation/Validation.php Line 326 in e2e5eca
The |
@paulbalandan Yes, this might be confusing and a little too "magical". Also it would introduce a breaking compatibility, since this bug is valid only if we want to display errors via session. I was thinking more about adding some new (optional) value to validation array, like: 'categories.*' => [
'rules' => 'is_not_unique[categories.id]',
'label' => 'Categories',
'as' => 'categories',
], With a note in the user guide that There is a workaround for this bug, so it's nothing urgent, I think. |
It seems to be a good idea from michals, although it is not something urgent to solve since it can be solved with this |
Since v4.2 CodeIgniter4/tests/system/Validation/ValidationTest.php Lines 873 to 879 in 6b077b7
Ref #5609 So it seems
CodeIgniter4/tests/system/Validation/ValidationTest.php Lines 881 to 885 in 6b077b7
|
So this does not seem a bug. |
Hello I am trying to print the errors when I validate an array structure for example:
then I try to print the errors in my html but it cannot show them, I suppose it is because of the key format that the function to obtain the errors returns
I think it is not the most practical way to return errors when it comes to array validations :(
thanks for everything!
The text was updated successfully, but these errors were encountered: