Fox Comment Box

Summary: Adding a comment form using Fox Version: 2006-04-03a Prerequisites: pmwiki 2.2.0 Status: Maintainer: HansB? Categories: Forms CMS, Comments Fox

Questions answered by this recipe

How can I add a comment form to a page, so users can add comments (even though they may not be logged on)?


You can add a comment form (commentbox) using Fox. Comments can be placed on the same page or a different target page, and appended or prepended relative to the form or a different location. appended comments appear in chronological order (last below previous), prepended comments in reverse chronological order (last on top).

The following is an example for a commentbox markup. The comment box uses a template page, with its markup shown later.


(:fox cbox put=aboveform template=Site.FoxCommentTemplate:)
|| Heading:||(:input text heading size=60:)
|| ||'''Your Message''' ||
|| ||(:input textarea comment cols=60 rows=6:) ||
|| Author:||(:input text author value='{$Author}' :) (:input submit post Enter:) ||
(:foxend cbox:)

If you need Captcha? or AccessCode enabled (for wikis which allow any visitor to post a comment), set $EnablePostCaptchaRequired = 1; and include Captcha? recipe, or $EnableAccessCode = true; , and use the following (as example):

Site.FoxCommentBox with Captcha or Access Code

(:fox cbox put=aboveform template=Site.FoxCommentTemplate:)
(:input hidden accesscode {$AccessCode}:)
|| Heading:||(:input text heading size=60:)
|| ||'''Your Message''' ||
|| ||(:input textarea comment cols=60 rows=6:) ||
(:if enabled EnableAccessCode:)
|| ||Enter value {$AccessCode} (:input text access size=3 class=inputtext:)
      (:input hidden accesscode {$AccessCode}:)  <- Have you entered the code number?||
(:if enabled EnablePostCaptchaRequired:)
|| ||Enter value {$Captcha} (:input captcha class=inputtext:) <- Have you entered the code number?||
|| Author:||(:input text author value='{$Author}' :) (:input submit post Enter:) ||
(:foxend cbox:)

Both examples can be varied in many ways, both in layout and in function.
Each comment gets posted on the location above the form (with put=aboveform).
Instead of using put=aboveform or some other put= option, you could use (:foxappend cbox:) or (:foxprepend cbox:) as marker on the page or a different target page.

  • (:foxappend cbox:) - the latest comment will be put above the other comments
  • (:foxprepend cbox:) - the latest comment will be put below the other comments (chronological)

To post to a different page use as first line in the fox form markup above:

  • (:fox cbox put=top target=PageName

To post to a PageName-Comments page, use:

  • (:fox cbox put=top target={*$FullName}-Comments:)

Include the comments on PageName-Comments in the current page, and the CommentForm with:

  • (:include {*$FullName}-Comments:)
  • (:include Site.FoxCommentBox:)


(:div1 class=messagehead:)
[-{$$(date d.m.Y - H:i)}-] &nbsp; (:if auth edit:){[foxdelrange]}(:if:)

This template gives a formatting to each comment post. It also adds a post delete button, for 'edit' authorised users. (date:...) can be formatted in various ways. CSS classes messagehead and messageitem allow CSS styling. I used those names because CommentBoxPlus? is using them, and the skins Gemini, FixFlow and Triad have built in color support for those styles.

In any case these are just simple examples, lots of different comment forms can be built.

For general use put the FoxCommentBox and FoxCommentTemplate into the Site group (or change the template= parameter to suit your location). Then you can add a commentbox in any page with

(:include Site.FoxCommentBox:)

Posting permissions

By default Fox allows posting by any user who got edit permission to the (target) page.
To allow users without edit permission to post to edit-protected pages, you need to set $FoxAuth = 'read'; in a local config file, best as a group or page customisation on for instance local/SomeGroup.php or local/SomeGroup.SomePage.php file. You will also need to add the group or page to $FoxPagePermissions, best done on Site.FoxConfig

If you need users to post to a read-protected (private) page, you need to set $FoxAuth = 'ALWAYS'; for that page.
See working example CommentBox


Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".


See Also