FoxCommentBox
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)?
Description
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 top or bottom of the page or a marker in a special 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. Comments are placed below a heading of !!Comments
which serves as a placement marker.
If only logged in users shall be able to post comments, have a look at FoxAuthUserCommentBox.
Site.FoxCommentBox
(:fox cbox put=below mark=!!Comments 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=below mark=!!Comments 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?|| (:if:) || 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.
Instead of using a put= option to specify a location on the target page, you could use (:foxappend cbox:)
or (:foxprepend cbox:)
as marker on the page or a different target page. These markups are invisible and used only as markers.
(: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)
Note that the options put=aboveform and put=belowform only work if the form is part of the page, and not included with an (:include ..:)
markup.
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:)
Site.FoxCommentTemplate
#foxbegin# (:div1 class=messagehead:) >>rfloat<< [-{$$(date d.m.Y - H:i)}-] (:if auth edit:){[foxdelrange]}(:if:) >><< !!!!!{$$author} (:div1end:) >>messageitem<< '''{$$heading}''' >>messageitem<< {$$comment} >><< #foxend#
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
Notes
Release Notes
See Also
Contributors
Comments
See discussion at FoxCommentBox-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.