diff options
Diffstat (limited to '_functions/submitComment.php')
-rw-r--r-- | _functions/submitComment.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/_functions/submitComment.php b/_functions/submitComment.php new file mode 100644 index 0000000..d96d39a --- /dev/null +++ b/_functions/submitComment.php @@ -0,0 +1,25 @@ +<?php + +function submitComment() +{ + // Get the content sent from the comment form + $comment = htmlentities($_POST['userContent']); + $postURL = $_POST['postURL']; + + // Set default values if blank + if (isset($_POST['userName']) && trim($_POST['userName']) !== "") { + $username = $_POST['userName']; + } else { + $username = null; + } + + // Create a 'Comment' object + include_once('_classes/Comment.php'); + $userComment = new Comment($comment, $postURL, $username); + + // Append comment to JSON file + $userComment->saveComment('_data/comments.json'); + + // Send the user back + header('Location: ' . $postURL . '#comments'); +}
\ No newline at end of file |