krz/php-blog
A PHP blogging system with built-in static comments.
clone: git clone https://gitbay.org/krz/php-blog.git
main: _functions/submitComment.php · raw
1<?php
2
3function submitComment()
4{
5 // Get the content sent from the comment form
6 $comment = htmlentities($_POST['userContent']);
7 $postURL = $_POST['postURL'];
8
9 // Set default values if blank
10 if (isset($_POST['userName']) && trim($_POST['userName']) !== "") {
11 $username = $_POST['userName'];
12 } else {
13 $username = null;
14 }
15
16 // Create a 'Comment' object
17 include_once('_classes/Comment.php');
18 $userComment = new Comment($comment, $postURL, $username);
19
20 // Append comment to JSON file
21 $userComment->saveComment('_data/comments.json');
22
23 // Send the user back
24 header('Location: ' . $postURL . '#comments');
25}