From f7e5ddcbc5a2c0018f528bc0fe4cfec9a28b3ec2 Mon Sep 17 00:00:00 2001 From: Kabirou ALASSANE Date: Sat, 18 May 2024 16:25:32 +0100 Subject: [PATCH] Set empty field to blank string before validation Addresses bug where validation fails on non-required fields that are not present in the data. By initializing missing fields to an empty string, validation rules like min, max, size, etc. can be properly applied without triggering an error due to an undefined index. Fixes #124 --- src/Validator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Validator.php b/src/Validator.php index 3b4d291..d3fe7db 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -124,6 +124,8 @@ protected function checkPasses(mixed $validator, string $field, ?string $ruleNam { if(!isset($this->data[$field]) && $ruleName !== 'required') return ; + $this->data[$field] = isset($this->data[$field]) ? $this->data[$field] : ''; + if (!$validator->passes($field, $this->data[$field], $this->data)) { $assert = isset($ruleName) && isset($this->messages[$field][$ruleName]);