changeset 35:a30aee3f6158

simple form handler for submitting a comment. This script just forwards the comment via eMail.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 01 Sep 2014 04:15:01 +0200
parents 822bec7ea32d
children 96084c11584a
files submit_comment.php
diffstat 1 files changed, 45 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/submit_comment.php	Mon Sep 01 04:15:01 2014 +0200
@@ -0,0 +1,45 @@
+<?php
+function get_slug()
+{
+    $slug = htmlspecialchars($_POST['Slug']);
+    if (empty($slug))
+    {
+        die('POST request did not include value for required key "Slug"');
+    }
+    return $slug;
+}
+
+if ($_SERVER['REQUEST_METHOD'] == 'POST')
+{
+	$recipient = 'blog@xanthippe.ping.de';
+    $slug = get_slug();
+
+    $author = htmlspecialchars($_POST['Author']);
+    $comment = htmlspecialchars($_POST['Comment']);
+    $date = date('Y-m-d H:i:s');
+
+	$message = 'Author: ' . $author . PHP_EOL 
+		. 'Date: ' . $date . PHP_EOL . PHP_EOL 
+		. $comment;
+
+	$subject = 'New blog post comment on article ' . $slug;
+    mail($recipient, $subject, $message);
+
+?>
+
+<html>
+    <head>
+        <title>Your comment was posted</title>
+    </head>
+    <body>
+        <h1>Thank you</h1>
+        <p>
+        Your comment was posted and will appear on the blog as soon as a moderator has reviewed it.
+        </p>
+        <a href="http://xanthippe.duckdns.org/blog/">Back to the blog</a>
+    </body>
+</html>
+
+<?php
+}
+?>