Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

FoxCommentBox

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)?

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. Commnets are placed below a heading of !!Comments which serves as a placement marker.

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)}-] &nbsp; (: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

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".

Comments

Because if lost 6 hours of few little problems, I post my solution here :

Page with form

(:if ! exists {*$FullName}-Comments:)No comments for the moment(:if:)

(:include {*$FullName}-Comments :)

(:fox formComment:)
(:if ! exists {*$FullName}-Comments:)
(:foxadd Site.FoxTemplate-FirstComment=>{*$FullName}-Comments :)
(:if exists {*$FullName}-Comments:)
(:foxadd Site.FoxTemplate-Comment=>{*$FullName}-Comments :)
(:if:)
(:foxcheck comment msg='You must post a comment' :)
(:foxcheck author msg='You must post an author' :)
(:foxmessage formComment comment :)\\
(:foxmessage formComment author :)\\
(:input textarea comment rows=3 cols=60:)\\
Author : (:input text author value='{$Author}' size=30 :)\\
Enter value {$Captcha} (:input captcha:) <- Captcha\\
(:input submit post value='Post':)
(:foxend formComment:)

Page Site.FoxTemplate-Comment

#foxbegin#
(:div1 class=messagehead:)
>>rfloat<<   
[-{$$(date d.m.Y - H:i)}-]
>><<
!!!!!{$$author}
(:div1end:) 
>>messageitem<<
{$$comment} 
>><<
#foxend#

Page Site.FoxTemplate-FirstComment

!Comments (directive foxprepend must have a text before !!)

(:foxprepend formComment:) (warning : no space before the name of the form)

#foxbegin#
(:div1 class=messagehead:)
>>rfloat<<   
[-{$$(date d.m.Y - H:i)}-]
>><<
!!!!!{$$author}
(:div1end:) 
>>messageitem<<
{$$comment} 
>><<
#foxend#

This is perhaps a misunderstanding. The first word in the (:fox :) markup directive after fox is the name of the form. For instance in (:fox cbox ...:) cbox is the form name. Directive (:foxprepend:) can catch output from this form only by using (:foxprepend cbox:). In the example above formComment is the name of the form, not Comment. HansB December 05, 2008, at 04:05 PM

See Also

Contributors

User notes?: If you use, used or reviewed this recipe, you can add your name. The following format is recognized:
* (+) Optional positive comment. Name, date
* (-) Optional negative comment. Name, date

These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on February 10, 2010, at 03:06 AM