2nd February 2004, terribly early in the morning | Comments (12)
If you’ve posted a comment to this site before now, you’ll know that after hitting the submit button you’re redirected to see your newly posted comment, nestling amongst it’s friends, in loco.
Why does that occur? Well it’s way of reassuring you that all is well, that what you expected to happen, has happened — that your comment has been posted.
That’s all very well for comments that can go live immediately, but what about comments that require moderation? They don’t appear on the site until I’ve given them the all-clear, so what kind of feedback do I provide to their posters? Where are they redirected to?
Well, I’ll show you, and I’ll also pop some code up so you can grab it if you want.
After the user has written their comment and hit the submit button I do a quick check to see if comment moderation is turned on for the post in question. This check returns a variable called $cmnt_mod
. Based on this variable when I insert the comment into the database I set a flag — 0 or 1 — that determines if the comment can go live, or if it’s to await moderation.
All straight forward stuff.
Once the comment has been inserted into the database it’s time to redirect the user to one of two places, either: 1) to their newly posted, and live comment; or 2) to a place holder which tells them that their comment is being held for moderation.
This is how I do it:
<?php
// if cmnt moderation is off
if ($cmnt_mod == 0)
{
// redirect to comment
header("Location: http://1976design.com/blog/archive/$m/$d/$t/#cmnt$last_insert_id");
exit;
}
else
{
session_start();
$_SESSION['just_posted'] = 1;
// redirect to comment holder
header("Location: http://1976design.com/blog/archive/$y/$m/$d/$t/#cmnt-holder");
exit;
}
?>
The first instance requires no extra coding on my part; the user’s comment will be printed out along with all the others and the browser will jump them down so they can see it (using the comment’s ID as an anchor).
The second redirect option does require a bit of extra work: a few lines of PHP to be added on to the end of the list of comments:
<ol>
<?php
// loop through all the comments and print them
// out as ordered list items
// [php code to do that goes here]
// if comment moderation is on and a comment has
// been posted, then insert a comment holder so
// the user knows what has happened to their comment
if (!empty($_SESSION['just_posted']))
{
?>
<li id="cmnt-holder">
<h3>Comment place holder</h3>
<p>Your comment is currently being held for moderation: if it's a good comment then it'll be posted here; if it's spam then it'll be deleted. Thanks for your patience.</p>
</li>
<?php
// reset session variable
$_SESSION['just_posted'] = '';
}
?>
</ol>
And there you are, the user is faced with a one-time message that gives them some idea of what’s happened to their comment. It also provides continuity; the user will always be redirected after posting, and they only have to look on screen to understand the outcome of their actions.
I know that was pretty short and sweet, but I hope that it proves useful to someone.
Jump up to the start of the post ↑
A collection of miscellaneous links that don't merit a main blog posting, but which are interesting none-the-less.
Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we.— George W Bush (9)
Stuff from the intersection of design, culture and technology.(3)
A selection of blogs I read on a regular basis.