1
0
Fork 0

Add "equals" parameter to form validator

master
Anonymous Contributor 2023-08-23 18:16:34 +02:00
parent 6a6e7db2ce
commit 390aa89d9f
1 changed files with 7 additions and 2 deletions

View File

@ -9,11 +9,16 @@ class FormValidator {
public function isValid(array $req) { public function isValid(array $req) {
foreach($fieldValidation as $field => $params) { foreach($fieldValidation as $field => $params) {
if($params['required'] && !isset($req[$field])) { if($params['required'] && (!isset($req[$field]) || strlen($req[$field]) == 0)) {
return false; 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; return false;
} }
} }