Skip to content

Commit 33a95a8

Browse files
new commit change: for 0 values
1 parent fd379bd commit 33a95a8

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/UltimateValidator.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,16 @@ public function submit(array $data, ?bool $allowedType = false, callable $before
123123

124124
//check response error from input flags
125125
$flags = $this->createFlags($keyPair);
126+
126127
//allowed error handling type
127128
if($allowedType == false){
128-
if(in_array($flags, [false, '!isset'])){
129+
if($flags === false || $flags === '!isset'){
129130
$this->message = $message;
130131
$this->error = true;
131132
break;
132133
}else{
133134
$this->error = false; // set to false
134-
135+
135136
//operator function checker
136137
$this->operator = $this->operatorMethod($keyPair);
137138

@@ -150,7 +151,7 @@ public function submit(array $data, ?bool $allowedType = false, callable $before
150151
}
151152
}
152153
else{
153-
if(in_array($flags, [false, '!isset'])){
154+
if($flags === false || $flags === '!isset'){
154155
if(!in_array($keyPair['variable'], array_keys($this->message))){
155156
$this->message[$keyPair['variable']] = $message;
156157
}
@@ -353,13 +354,11 @@ public function getForm($type = null)
353354
* @return array|object|string|null
354355
*/
355356
public function old($key = null)
356-
{
357+
{
357358
// in array keys
358359
$formData = $this->getForm()['form'];
359-
if(is_array($formData)){
360-
if(in_array($key, array_keys($formData))){
361-
return $formData[$key];
362-
}
360+
if(in_array($key, array_keys($formData))){
361+
return $formData[$key];
363362
}
364363
return;
365364
}
@@ -412,8 +411,10 @@ private function createFlags(array $flag)
412411

413412
default:
414413
$type = htmlspecialchars(filter_input($this->type, $flag['variable']), ENT_HTML5);
415-
if(empty($type))
414+
// mostly for value of 0
415+
if(empty($type) && $type != '0') {
416416
$type = false;
417+
}
417418
break;
418419
}
419420
}else{
@@ -430,13 +431,15 @@ private function createFlags(array $flag)
430431
private function operatorMethod(?array $flag = null)
431432
{
432433
$this->operator = null;
434+
433435
//comparison operator command
434436
if(isset($flag['operator']) && !empty($flag['operator'])){
435437
$this->operator = 'error';
436438
//value check command
437439
if(isset($flag['value']))
438440
$this->operator = $this->createOperator($flag);
439441
}
442+
440443
return $this->operator;
441444
}
442445

@@ -552,7 +555,7 @@ private function createOperator($flag)
552555
}
553556

554557
}
555-
558+
556559
return $this->operator;
557560
}
558561

0 commit comments

Comments
 (0)