krz/php-blog

A PHP blogging system with built-in static comments. blog comments php static

_functions/submitComment.php

main
php-blog/_functions/submitComment.php history · blame · raw

25 lines · 671 bytes

 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}