Howto extend the comment form with additional fields

This document explains how to extend the comment form with additional fields in an add-on product. uses the plone.z3cform.fieldsets package which provides support for modifications via “extender” adapters. The idea is that a third party component can modify the fields in a form and the way that they are grouped and ordered.


This howto applies only to >= 2.0.4 and >= 1.1.2 Prior versions will not store the extended fields on the comment.

See also

The source code of this howto can be found here:

Howto extend the comment form with an additional “website” field

First, create a new plone package:

$ paster create -t plone example.commentextender

Go to the main directory of the package (example.commentextender/example/commentextender) and create a new file

This file contains the ICommentExtenderFields interface definition with a “website” field, a persistent CommentExtenderFields class to store the value of the “website” field, a CommentExtenderFactory to create the CommentExtenderFields, and a CommentExtender class to extend the default comment form with the “website” field:

from persistent import Persistent

from z3c.form.field import Fields

from zope import interface
from zope import schema

from zope.annotation import factory
from zope.component import adapts
from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer

from plone.z3cform.fieldsets import extensible

from import CommentForm
from import Comment

# Interface to define the fields we want to add to the comment form.
class ICommentExtenderFields(Interface):
    website = schema.TextLine(title=u"Website", required=False)

# Persistent class that implements the ICommentExtenderFields interface
class CommentExtenderFields(Persistent):
    website = u""

# CommentExtenderFields factory
CommentExtenderFactory = factory(CommentExtenderFields)

# Extending the comment form with the fields defined in the
# ICommentExtenderFields interface.
class CommentExtender(extensible.FormExtender):
    adapts(Interface, IDefaultBrowserLayer, CommentForm)

    fields = Fields(ICommentExtenderFields)

    def __init__(self, context, request, form):
        self.context = context
        self.request = request
        self.form = form

    def update(self):
        # Add the fields defined in ICommentExtenderFields to the form.
        self.add(ICommentExtenderFields, prefix="")
        # Move the website field to the top of the comment form.
        self.move('website', before='text', prefix="")

See also

Now register the CommentExtenderFactory and CommentExtender Classes that has been created by adding the following lines to your configure.zcml:

  provides=".commentextender.ICommentExtenderFields" />

  provides="plone.z3cform.fieldsets.interfaces.IFormExtender" />

Create a new Plone instance, globally allow commenting, allow commenting on a content object and you will see a comment form with an additional “website” field.

Since we do not only want to store the “website” value on the comments, but also to show these values for existing comments, we have to override the comments viewlet. The easiest way to do this is to use z3c.jbot.

First, add z3c.jbot. to the of the example.commentextender package:


Next, create a new directory called “overrides” inside the example.commentextender package and register it together with z3c.jbot in your configure.zcml:



  <include package="z3c.jbot" file="meta.zcml" />

    directory="overrides" />


Copy to the overrides directory we just created and rename to

You can now add code to show the website attribute to the documentByLine:

<div class="documentByLine" i18n:domain="">
    <div class="commentWebsite"
       <a href=""
          tal:attributes="href reply/website"

Restart your Plone instance and you will see the “website” field in the documentByLine next to the comments.

Table Of Contents

Previous topic


Next topic


This Page