Post #213

Providing feedback on comment submission

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 submission

A screenshot showing a comment place holder

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:

  1. <?php
  2. // if cmnt moderation is off
  3. if ($cmnt_mod == 0)
  4. {
  5. // redirect to comment
  6. header("Location:$m/$d/$t/#cmnt$last_insert_id");
  7. exit;
  8. }
  9. else
  10. {
  11. session_start();
  12. $_SESSION['just_posted'] = 1;
  14. // redirect to comment holder
  15. header("Location:$y/$m/$d/$t/#cmnt-holder");
  16. exit;
  17. }
  18. ?>
  19. Download this code: 213a.txt

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:

  1. <ol>
  2. <?php
  3. // loop through all the comments and print them
  4. // out as ordered list items
  5. // [php code to do that goes here]
  7. // if comment moderation is on and a comment has
  8. // been posted, then insert a comment holder so
  9. // the user knows what has happened to their comment
  10. if (!empty($_SESSION['just_posted']))
  11. {
  12. ?>
  13. <li id="cmnt-holder">
  14. <h3>Comment place holder</h3>
  16. <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>
  17. </li>
  18. <?php
  19. // reset session variable
  20. $_SESSION['just_posted'] = '';
  21. }
  22. ?>
  23. </ol>
  24. Download this code: 213b.txt

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

Comments (12)

Jump down to the comment form ↓

  1. Cheah Chu Yeow:

    This is a nice post! Thanks for sharing that. I was wondering how you did it so that the comment placeholder disappears on a 2nd visit to the same page.

    I'm sure you know I found it a little confusing when I double-posted the last time I made a comment here. Here's why: I wasn't aware comments moderation was on (since there wasn't any before I think), so after my submission, I expected to see my comment. Instead I saw some text that didn't have my name on it and I didn't read further, thinking it was another person's comment. I know, I know - I was a little muddle-headed there. But I think it would help if 1) you made the comment placeholder a little more distinct for the minority who are like me, and 2) have it indicated on your comment form that comments moderation is turned on if it is so (if there already is indication now, I apologize again for not noticing - I'm like to scan pages a lot and miss certain details).

    Hope that makes sense.

    Posted 1 hour, 48 minutes after the fact
    Inspired: ↓ Cheah Chu Yeow, ↓ Dunstan
  2. Cheah Chu Yeow:

    Woah there, I went back to your older posts and notice that you do actually indicate that comments moderation is turned on (below the "Preview" and "Post" buttons - see Dunstan's older blog entries). Scratch that :)

    Posted 1 hour, 51 minutes after the fact
    Inspired by: ↑ Cheah Chu Yeow
    Inspired: ↓ Dunstan
  3. Dunstan:

    Maybe it needs moving up, so it's above the submission buttons?
    Or maybe I can stick your name into the placeholder... or bold 'Your post is currently being held for moderation'?

    Hmm, I'll think about that. Thanks Cheah.

    Posted 7 hours, 5 minutes after the fact
    Inspired by: ↑ Cheah Chu Yeow, ↑ Cheah Chu Yeow
  4. Cheah Chu Yeow:

    Hmm... Moving up sounds good to me. As for the other thing, I prefer it bolding or highlighting the message.

    Best way out: get feedback from your users. I'm sure you get tons of visitors and I think they'd have good suggestions.


    PS. First name's Chu Yeow :)

    Posted 7 hours, 22 minutes after the fact
  5. Spike:

    Yeow is officially the greatest name ever. How is that pronounced, if you don't mind me going off topic a little?

    Posted 8 hours, 39 minutes after the fact
    Inspired: ↓ Cheah Chu Yeow
  6. Cheah Chu Yeow:

    Eh... Yeah... Name's Chu Yeow (2 words). Singaporean, to (possibly) pre-empt your next question.

    Pronounced as it looks to be... "Chu" like "choo" in "choo choo train" (only a tad less drawn out), "Yeow" as in "yeow! that hurt!".

    Posted 12 hours, 11 minutes after the fact
    Inspired by: ↑ Spike
  7. Colin D. Devroe:

    This is definitely nicer than seeing a Monkey message, like most people would have put. Example: "423 well-trained and learned Monkeys are perusing your comment. If it passes their 187 point check, only then will it be posted. Otherwise, expect to see it displayed in public to be made fun of."

    Posted 15 hours, 22 minutes after the fact
  8. Sian:

    Thank you, thank you very much.

    Posted 16 hours, 49 minutes after the fact
  9. David Collantes:

    Would anyone be willing to implement this as a plugin to MovebleType or a PHP add-on for the same CMS (MT)?

    That would a an awesome thing to have!

    Posted 19 hours, 22 minutes after the fact
    Inspired: ↓ Dunstan
  10. Dunstan:

    Personally I don't know anything about MT, so maybe you could ask on the MT developers site (is there one?) and point people here for an explanation of what you want.

    I'd be happy to help an MT developer out if they need a better explanation, but I'm sure people can get it from what I've written.

    Remember the CC license this stuff is published under:

    Posted 19 hours, 34 minutes after the fact
    Inspired by: ↑ David Collantes
  11. Joseph:

    Now this is a terrible bit of pedantry, but I feel obliged to point out (in reference to your "Commentors that inspired this post" line in each comment block) that the not-so-neologistic noun describing "people who make comments" is "commentators". I know it sounds odd, so I will bow to Webster's wisdom and accept "commenters".

    On the same note, would you be willing to rephrase it from "that inspired this post" to "who inspired this post"?

    Or you could get around both issues entirely with "Comments that inspired..."

    My pedantic whims are now sated. Thanks for bearing with me. God I hope there are no spelling errors in this post.

    Posted 2 weeks after the fact
  12. Indranil:

    Must ... try ... and ... learn ... PHP ...

    Posted 8 months, 3 weeks after the fact

Jump up to the start of the post

Add your comment

I'm sorry, but comments can no longer be posted to this blog.