summaryrefslogtreecommitdiff
path: root/create_thread.php
diff options
context:
space:
mode:
authorcflip <36554078+cflip@users.noreply.github.com>2021-05-15 09:15:58 -0600
committerGitHub <noreply@github.com>2021-05-15 09:15:58 -0600
commit45acfc48b3dd80b945a1501edea9ad4faa700c0f (patch)
tree87319e8b64789564e5d9ae227361593c419d905b /create_thread.php
parent87b1dfd1f77b08915ee5e905da45e316ba2c0e7d (diff)
parent2b03ca63d06ec5da45c887ef7cb3daa35a8642f7 (diff)
Merge pull request #16 from cflip/h5p9sl
Add error handling
Diffstat (limited to 'create_thread.php')
-rw-r--r--create_thread.php19
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);