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 --- create_thread.php | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'create_thread.php') diff --git a/create_thread.php b/create_thread.php index d01eb26..11b278c 100755 --- a/create_thread.php +++ b/create_thread.php @@ -42,36 +42,23 @@ if (!Session::get()->is_signed_in()) { validate_post_content($_POST['post_content']); + $thread_subject = $form->validate_thread_subject($_POST['thread_subject']); + $thread_category = $form->validate_thread_category($_POST['thread_cat']); - $errors = array(); - if (empty($thread_subject) or !$thread_subject) { - $errors[] = 'Thread subject cannot be empty'; - } - if (empty($post_content) or !$post_content) { - $errors[] = 'Thread body cannot be empty'; - } + $form->on_success(function () use ($post_content, $thread_subject, $thread_category) { + $thread_id = Thread::create($thread_subject, $thread_category); + Post::create($post_content, $thread_id, $thread_category); - if (!empty($errors)) { - $errstr = 'Please check the following problems: