diff options
Diffstat (limited to 'create_thread.php')
-rw-r--r-- | create_thread.php | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/create_thread.php b/create_thread.php index 6fb7df9..976bd9f 100644 --- a/create_thread.php +++ b/create_thread.php @@ -10,6 +10,7 @@ <h2>Create a new thread</h2> <?php include_once 'includes/Session.php'; +include_once 'includes/error.php'; if (!Session::get()->is_signed_in()) { trigger_error('You must be <a href="signin.php">signed in</a> to create a thread.'); exit(); @@ -26,7 +27,7 @@ if (!Session::get()->is_signed_in()) { $categories = get_all_categories(); if (count($categories) == 0) { - echo 'There are no categories to post to!'; + trigger_error('There are no categories to post to!'); } else { echo '<select name="thread_cat">'; @@ -44,14 +45,28 @@ if (!Session::get()->is_signed_in()) { <?php include_once 'includes/functions_post.php'; include_once 'includes/functions_thread.php'; +include_once 'includes/error.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $post_content = filter_input(INPUT_POST, 'post_content', FILTER_SANITIZE_STRING); $thread_subject = filter_input(INPUT_POST, 'thread_subject', FILTER_SANITIZE_STRING); $thread_cat = filter_input(INPUT_POST, 'thread_cat', FILTER_SANITIZE_NUMBER_INT); + $errors = array(); if (empty($thread_subject) or !$thread_subject) { - echo 'Thread subject cannot be empty'; + $errors[] = 'Thread subject cannot be empty'; + } + if (empty($post_content) or !$post_content) { + $errors[] = 'Thread body cannot be empty'; + } + + if (!empty($errors)) { + $errstr = 'Please check the following problems: <ul>'; + foreach ($errors as $err) { + $errstr .= '<li>' . $err . '</li>'; + } + $errstr .= '</ul>'; + trigger_error($errstr); } else { $thread_id = create_thread($thread_subject, $thread_cat); create_post($post_content, $thread_id, $thread_cat); |