From 633ea850f9293986b39162a6ac979149e494976b Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 22 Dec 2022 18:55:58 -0500 Subject: [PATCH] Added new FN to check for submit and validation... --- src/bootstrap/safer_io.php | 14 +++++++++++++- src/bootstrap/validator.php | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/safer_io.php b/src/bootstrap/safer_io.php index 7426be4..3c56f69 100644 --- a/src/bootstrap/safer_io.php +++ b/src/bootstrap/safer_io.php @@ -342,6 +342,13 @@ final class safer_io { self::$JSON_POST_DATA = self::get_json_post_data(true, $levels_deep); } + public static function required_fields_were_NOT_all_submitted(array $data): bool { + $field = $data['name'] ?? false; + $empty = $data['meta'][$field]['empty'] ?? true; + $required = $data['meta'][$field]['validation_rules_set'] ?? false; + return ($empty && $required); + } + private static function sanitize_helper( string $from, string $input_field_name, @@ -386,6 +393,8 @@ final class safer_io { $messages[$input_field_name] = $a->validation_message; } + $meta[$input_field_name]['validation_rules_set'] = (count($rules)) ? true : false; + $db = (isset($a->skip_the_db)) ? $a->skip_the_db : false; $meta[$input_field_name]['type'] = $field_type->name; $meta[$input_field_name]['skip_db'] = $db; @@ -394,14 +403,17 @@ final class safer_io { $safer_data = null; $safer_db_data = null; $safer_html_data = null; + $meta[$input_field_name]['empty'] = true; } else { $field_filter_resolved = $field_type->resolve(); + + $meta[$input_field_name]['empty'] = false; $safer_data = $user_text; if ($field_type == FIELD_FILTER::email) { $safer_data = substr($safer_data, 0, 254); } - + $safer_data = filter_var($safer_data, FILTER_DEFAULT, $field_filter_resolved); // FallBack: These field types should never allow arrays anyways diff --git a/src/bootstrap/validator.php b/src/bootstrap/validator.php index eb4ca9d..5911043 100644 --- a/src/bootstrap/validator.php +++ b/src/bootstrap/validator.php @@ -36,7 +36,9 @@ class validator { } else { $dataset[] = $data[$field]; } - } + } else { + $dataset[] = null; // If field is null, force null set + } return $dataset; }