From 04d30cfe16e11140c8efb22afd61f2386c35cd87 Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Tue, 20 Jul 2021 17:25:03 -0600 Subject: Handle input validation in abstract Form class --- includes/form/Form.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 includes/form/Form.php (limited to 'includes/form/Form.php') diff --git a/includes/form/Form.php b/includes/form/Form.php new file mode 100644 index 0000000..3f1bd62 --- /dev/null +++ b/includes/form/Form.php @@ -0,0 +1,45 @@ +errors[] = $error_string; + $this->success = false; + } + + public function success(): bool + { + return $this->success; + } + + public function html_error_list(): string + { + if ($this->success) + return ""; + + if (count($this->errors) > 1) { + $result = ''; + return $result; + } else { + return $this->errors[0]; + } + } + + public function on_success(Closure $param) + { + if ($this->success()) { + $param(); + } else { + echo '

Please check the following problems:

'; + trigger_error($this->html_error_list()); + } + } +} \ No newline at end of file -- cgit v1.2.3