From 390aa89d9f66d811554930e39e6f55b5ce7037de Mon Sep 17 00:00:00 2001 From: Anonymous Contributor Date: Wed, 23 Aug 2023 18:16:34 +0200 Subject: [PATCH] Add "equals" parameter to form validator --- classen/FormValidator.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/classen/FormValidator.php b/classen/FormValidator.php index 097bd37..5a0955f 100644 --- a/classen/FormValidator.php +++ b/classen/FormValidator.php @@ -9,11 +9,16 @@ class FormValidator { public function isValid(array $req) { foreach($fieldValidation as $field => $params) { - if($params['required'] && !isset($req[$field])) { + if($params['required'] && (!isset($req[$field]) || strlen($req[$field]) == 0)) { return false; } - if(isset($params['regex']) && !preg_match($params['regex'], $req[$field])) { + if(isset($params['regex'])) { + if(!preg_match($params['regex'], $req[$field])) { + return false; + } + } + else if(isset($params['equals']) && $params['equals'] !== $req[$field]) { return false; } }