diff options
author | Christian Cleberg <hello@cleberg.net> | 2023-05-22 15:18:52 -0500 |
---|---|---|
committer | Christian Cleberg <hello@cleberg.net> | 2023-05-22 15:18:52 -0500 |
commit | deb20fdfca35c64066fe4e375099350dc77ea408 (patch) | |
tree | 8be0f7541652e4e8f89fc4dd603fae7accf4ee24 /_functions/submitComment.php | |
download | php-blog-deb20fdfca35c64066fe4e375099350dc77ea408.tar.gz php-blog-deb20fdfca35c64066fe4e375099350dc77ea408.tar.bz2 php-blog-deb20fdfca35c64066fe4e375099350dc77ea408.zip |
initial commit
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 |