Summary: Adds a simple form to post comments
Version: 2.0.19 (released 2007-10-31)
Status: Stable
Prerequisites: pmwiki 2.0 and above; 2.1 recommended
Maintainer: jr
Discussion: CommentBox-Talk
Categories: Forms CMS Blog, Comments


Give authors a simple way to add a comment box to a wiki page.


  • commentbox.phpΔ (merges changes from commentbox2 and some of Mike's suggestions; now with division styling)

See also

  • CommentBoxPlus for a modified version with additional features.
  • CommentDb - an alternative solution, that stores comments in a database. For this price provides convenient comment pagination and RSS-feed of the comments.

Update: commentbox.phpΔ and commentboxplus.phpΔ are no longer allowing edit access to pages if no edit permission is present (a former security risk). - Jan 30, 2006.

Note: this uses the run-in head markup to lay out comments, so requires the MarkupExtensions to work correctly. However, the variables can also be redefined to work with a standard PmWiki install.


Put commentbox.php into the cookbook/ directory.

Add the following to local/config.php



Following the (:searchbox:) directive naming convention, there are 2 new directives:

(:commentbox:) !!!!12 July 2005 !21:39 by '''[[~Pm]]'''!post again !21:39 by '''[[~Pm]]'''!Test comment posts comments latest first
(:commentboxchrono:) posts comments latest last

You can put (:commentbox:) in a GroupHeader -- all comments get posted at the top of the page.

You can put (:commentboxchrono:) in a GroupFooter -- all comments get posted at the bottom of the page.

If the page name ends in Journal or Diary (configurable), the script automatically inserts a comment box after the GroupHeader and before the text. You don't have to state e.g. (:commentbox:) anywhere for this feature (except loading in local/config.php of course)

Posting comments to other pages

This is a new feature.

The recipe also supports posting comments to different pages with the (:commentbox pagename:) option. As this is potentially a security risk, there are a number of controls in place using global variables that an administrator sets in local/config.php:

  • $EnablePostToAnyPage is false by default and cross-page commenting is disallowed; to enable cross-page comment posting, set to true
  • $EnableRedirectToCommentPage is false by default; to redirect the commenter to the comment page after posting, set to true
  • $AllowedPostToGroups is an empty array by default and comments are restricted to the current group; to enable cross-group posting, add the target group(s) to the array; for example, $AllowPostToGroups[] = 'Somegroup';

Format of comments

An administrator can control the format of comment entries using the following variables. See also samples in source.

Journal pages$JPDateFmt!!!!$Date!!!!!$Date
 $JPTimeFmtnn!$Time!nn'''$Time : '''
Diary pages$DPDateFmt!$Date!!!!!!$Daten
 $DPItemFmtnn: :n*
Message pages$MPDateFmt!!!!$Date!!!!!$Date
 $MPTimeFmtnn!$Time by '''$Author'''!nn'''$Time - ''$Author'' : '''
 $MPItemFmt(null string)n----

The $Date, $Time and $Author strings get str_replaced with the current values within the script. Note the $ for variables defined using " ... ". Administrators will want to test their use of "n" carefully -- the script author kept having too many or too few, leading to unexpected (and unwanted) results.

The latest version of commentbox.phpΔ includes heading and division styling by default, with the following variable settings (these use the run-in head markup, but this can be changed). jr
     SDV($DPItemFmt,"\n\n: :");
     SDV($MPTimeFmt,"\n\n>>message<<\n!\$Time by \$Author!");
          ">>message<<\n!!!!\$Date at \$Time by \$Author\n\n");

The default styling is

  h4.journalhead, h4.messagehead { background:#ffb; border-top:1px dotted #999; }
  .message, .journal, .diary {
      border:1px dotted #999;
New feature
By default, $commentboxaccesscode is false. If set to true in local/config.php before loading commentbox.php, it prompts the poster to enter a randomly-generated 3 digit number. This may deter comment spamming robots. The code also limits the number of links allowed in a post to 1. The $MaxLinkCount variable controls this.


  • 31 Oct 2007 improve security of posting comments to other pages
  • 11 Aug 2006 tidy styles and add $commentboxaccesscode to deter spammers
  • 02 July 2006 add (:commentbox PageName:) option to post to a specified page
  • 28 March 2006 fix bug if pages contain backslash markup, add heading class
  • 31 Jan 2006 prevent ?action=comment from bring up the edit page form
  • 21 Sep 2005 add div around each comment (light version of Hans' extension)
  • 01 Sep 2005 support $Time and $Author in $MPItemFmt
  • 11 May 2005 changed BasicAuth to PmWikiAuth
  • 14 Mar 2005 set Author to 'anon' if author field is blank
  • 27 Feb 2005 remove "wrap='virtual'" from textareas
  • 10 Jan 2005 tidy the format (thanks to Mike)
  • 28 Nov 2004 fix <th>...</td> errors
  • 13 Nov 2004 set the format of comment entries using variables that an administrator can control
  • 29 Oct 2004 modify PmWiki 1 script to work with PmWiki 2




See discussion at CommentBox-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.