Skip to content

Commit

Permalink
Set empty field to blank string before validation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BlakvGhost committed May 18, 2024
1 parent 69314ac commit f7e5ddc
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit f7e5ddc

Please sign in to comment.