Skip to content

Commit f6cf020

Browse files
Harrison IfeanyichukwuHarrison Ifeanyichukwu
Harrison Ifeanyichukwu
authored and
Harrison Ifeanyichukwu
committed
fix: fix requireIf checked and notChecked conditional key implementations
This fix now considers when the checkbox field is sent, in the case of api requests. Web browsers do not send unchecked checkbox fields
1 parent e67dfa3 commit f6cf020

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Handler.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,21 @@ protected function validateFields(array $fields, bool $required)
361361
}
362362
}
363363

364+
/**
365+
* tests if a value is falsy
366+
*
367+
*@param $value - the value to test
368+
*/
369+
protected function valueIsFalsy($value)
370+
{
371+
$value = strval($value);
372+
373+
if (preg_match('/^(false|off|0|nil|null|no|undefined)$/i', $value) || $value === '')
374+
return true;
375+
else
376+
return false;
377+
}
378+
364379
/**
365380
* runs data filteration on the given value
366381
*
@@ -425,7 +440,7 @@ protected function filterValue($value, array $filters)
425440
break;
426441

427442
case 'bool':
428-
if (preg_match('/^(false|off|0|nil|null|no|undefined)$/i', $value) || $value === '')
443+
if ($this->valueIsFalsy($value))
429444
$value = false;
430445
else
431446
$value = true;
@@ -699,12 +714,12 @@ protected function processRules()
699714
switch(strtolower($condition))
700715
{
701716
case 'checked':
702-
if (!is_null($_field_value))
717+
if (!$this->valueIsFalsy($_field_value))
703718
$required = true;
704719
break;
705720

706721
case 'notchecked':
707-
if (is_null($_field_value))
722+
if ($this->valueIsFalsy($_field_value))
708723
$required = true;
709724
break;
710725

0 commit comments

Comments
 (0)