CI4 validation, obtain an error on a field other than the controlled one |
Using validation, if a field does not match the rules, the specific field name is reported to show the error.
In my case, I retrieve the error array to report errors under the affected fields. In some cases I have to check if at least one element has been checked, inserted, combined, etc., etc. In these cases I have to report the error not under a field, but under a certain block of elements. If the field or fields were named "foo" or "foo[]" if they are for example a group of checkboxes, the error would be reported in the wrong places (at least for my needs). Is there any way, direct or indirect, to check the "foo" field, but report the error in the "bar" element? So if I check the rules for the "foo" field, and I have errors, return me in the array not foo but bar
(10-17-2022, 02:26 PM)kenjis Wrote:(10-17-2022, 08:34 AM)serialkiller Wrote: Is there any way, direct or indirect, to check the "foo" field, but report the error in the "bar" element? Hi kenjis, my problem is that bar is not a field but a div i tried this way, it works, but i don't know if it's the best way PHP Code: $errors = $this->model->errors(); If I have an error on the foo field, I change the errors array key from foo to bar |
Welcome Guest, Not a member yet? Register Sign In |