From d6c5c7735e3207ead7759375e444bc6b72045e49 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 5 Jan 2022 23:12:23 +0100 Subject: Validate fields by pattern and add more example fields --- src/App.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/App.php b/src/App.php index a155017..1a12f6a 100644 --- a/src/App.php +++ b/src/App.php @@ -257,9 +257,14 @@ class App */ public function validateSingleField($field) { + $value = $_POST[$field['name']] ?? ''; $field['is_valid'] = true; - if (($field['required'] ?? false) && empty($_POST[$field['name']])) { + if (isset($field['required']) && empty($value)) { + $field['is_valid'] = false; + } + + if (isset($field['validation']['pattern']) && preg_match_all('/' . $field['validation']['pattern'] . '/', $value) === 0) { $field['is_valid'] = false; } -- cgit v1.2.3