diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index b03badb9bf43..5dbf4b7f5d93 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -356,8 +356,10 @@ protected function processRules( $param = ($param === false) ? '' : $param; + $fieldForErrors = ($rule === 'field_exists') ? $originalField : $field; + // @phpstan-ignore-next-line $error may be set by rule methods. - $this->errors[$field] = $error ?? $this->getErrorMessage( + $this->errors[$fieldForErrors] = $error ?? $this->getErrorMessage( ($this->isClosure($rule) || $arrayCallable) ? (string) $i : $rule, $field, $label, diff --git a/tests/system/Validation/RulesTest.php b/tests/system/Validation/RulesTest.php index 844daab3f005..4844d898e3a9 100644 --- a/tests/system/Validation/RulesTest.php +++ b/tests/system/Validation/RulesTest.php @@ -948,8 +948,7 @@ public function testFieldExistsErrorMessage(): void $this->assertFalse($this->validation->run($data)); $this->assertSame( - // This errror message is not perfect. - ['fiz.bar.baz' => 'The fiz.*.baz field must exist.'], + ['fiz.*.baz' => 'The fiz.*.baz field must exist.'], $this->validation->getErrors() ); }