How to allow non-members to add non-anonymous comments
When configuring a plone site to allow for non-members to add comments, their feedback will always be marked as from 'Anonymous User'. Here's how to give them the option of supplying a name.
- allow anonymous comments by a) granting the
Reply to itempermission to theAnonymousrole in the ZMI. (Do this for the plone instance to enable sitewide discussion) and b) activating theAllow Discussioncheckbox in theportal_typesentry of (at least)Document. - Add a name field to 'discussion_reply_form':
<div class="field"> <label for="username" i18n:translate="label_name">Name</label> <input name="Creator" id="username" value="" alt="Submitter" title="Name" size="40" tabindex="" i18n:attributes="title" tal:attributes="tabindex tabindex/next;" /> </div> - Make the corresponding
discussion_replyscript use this, but only, if the user is not logged in, and if the field hasn't been left empty. This has the added benefit, that users who chose to leave the field empty will (correctly) be shown as 'anonymous':if not Creator: creator = context.portal_membership.getAuthenticatedMember().getUserName() else: creator = Creator id = context.createReply(title=title, text=text, Creator=creator)
You can download the entire scripts for your convenience: discussion_reply_form and discussion_reply.
(credits to James Cameron Cooper and Jon Stahl from the plone-user mailing list)
Jon:
I have figured out how to enable anonymous (unregistered) users to comment on items in Plone 2.0, but I'm wondering if there's an easy way to allow anonymous commenters to submit their name so that anonymous comments are shown as being from <name> rather than from "anonymous." I've already tried changing the "Creator" input item in the discussion_reply_form from hidden to visible. That allowed me to change the default "Anonymous User" value in the discussion form, but the posted comment still displayed as from "anonymous" after it was submitted, no matter what I entered as my name.
James:
Although the form defines that input, the script it submits to (discussion_reply) doesn't
honor it, or even pay attention.
You can customize that script to fix this by doing the following:
- add to the parameters 'Creator=None'
- replace this line:
creator = context.portal_membership.getAuthenticatedMember().getUserName()
with
if not Creator: creator = context.portal_membership.getAuthenticatedMember().\
getUserName()
else: creator = Creator
There are slightly more efficient variants, but this gets the job done with the
least amount of changes.
