Visitor comments and submitted content

Sites often permit visitors to leave comments - be they blog comments, visitor books or comments on Wiki pages.

Weceem supports a generic mechanism for visitors to create new content nodes via a form, filtered through the security policy.

This is, for example, how the default space implements comments on blogs. A widget is used to render a form to capture the comment fields and submit them to Weceem's content submission controller - where they are, if the security policy permits that kind of content at that URI, from that (anonymous) user - saved in an "unmoderated" status (see: security policy).

Creating a comment submission form

To allow users to submit content, you need to provide the data from the client browser - usually with a form that the user completes. You will usually do this inside a Widget node so that the code can be reused:

<g:hasErrors bean="${submittedContent}">
There were some errors on your submission, please check below

<wcm:submitContentForm parent="${parentContent}" type="org.weceem.content.WcmComment" success="${parentContent}">

<bean:require beanName="submittedContent" className="org.weceem.content.WcmComment"/>
<bean:field beanName="submittedContent" property="author" label="Your name"/>
<bean:field beanName="submittedContent" property="email"/>
<bean:input beanName="submittedContent" property="websiteUrl" label="Website URL"/>
<bean:input beanName="submittedContent" property="title"/>
<bean:field beanName="submittedContent" property="content" label="Your comment"/>
<input type="submit" class="button positive" value="Send comment"/>


Here, three different Grails taglibs are being used to create the form:

  1. g:hasErrors is a Grails tag used to detect any errors on the submittedContent data and alerts the user if so
  2. wcm:submitContentForm creates a form that will submit content of a specific type, as set in the "type" attribute. The "parent" attribute must be set to the node that will be the parent of the new content (or null for root content), and the "success" attribute is the repository URI path or node that should be shown after the content has been submitted - e.g. the original Blog Entry
  3. bean:* tags are from the Grails bean-fields plugin that is provided as part of Weceem. They make it easy to render sensible default fields, labels and error messages for properties of an object. In this case the object is the "submittedContent" bean used by the content submission form.

The form will include a link to the content submission controller. This controller will save the content if it is valid, or return to the existing content with the "submittedContent" object populated with the previous data and any errors attached. Using the bean:* tags of the Grails Bean-Fields plugin is merely a convenience, but is very useful as it will display the validation errors associated with each field inline in the form.

If the submission succeeds - which requires the user to have permission to create that type of content under the specified parent in the repository - it will redirect the user to the content specified in the "success" attribute.

The content will be in the "unmoderated" status, until an administrator updates the status to Published.

eMail Page   Print
      Delicious   submit to reddit