Welcome Guest, Not a member yet? Register   Sign In
CI4 validation, obtain an error on a field other than the controlled one
#3

(This post was last modified: 10-18-2022, 12:41 AM by serialkiller.)

(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?

No.
In that case, you should think that the error is in the "bar" element, not in the "foo" field.

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 (
$this->model->validation->hasError('foo')) {
    $errors['bar'] = $errors['foo'];
    unset($errors['foo']);


If I have an error on the foo field, I change the errors array key from foo to bar
Reply


Messages In This Thread
RE: CI4 validation, obtain an error on a field other than the controlled one - by serialkiller - 10-18-2022, 12:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB