Skip to content

Commit f7e5ddc

Browse files
committed
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
1 parent 69314ac commit f7e5ddc

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

src/Validator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ protected function checkPasses(mixed $validator, string $field, ?string $ruleNam
124124
{
125125
if(!isset($this->data[$field]) && $ruleName !== 'required') return ;
126126

127+
$this->data[$field] = isset($this->data[$field]) ? $this->data[$field] : '';
128+
127129
if (!$validator->passes($field, $this->data[$field], $this->data)) {
128130

129131
$assert = isset($ruleName) && isset($this->messages[$field][$ruleName]);

0 commit comments

Comments
 (0)