Save Author's Email for Anonymous Blog Comments

I am working on a control for Community Server where I need to capture the email address of the person making a comment. However, I don't need to store the email address if the person is already a registered member of the site since this information is stored already. What I did was utilize the CustomAction feature for the WeblogPostCommentForm and set the "AuthorEmail" extended attribute.

Here is how you can do it.

On the /themes/blogs/[default]/Post.aspx page locate your WeblogPostCommentForm and set the following:

<SuccessActions>
...

<
CSControl:CustomAction runat="server" OnCustomEvent="CommentFormSuccess" />
</SuccessActions>

This will wireup the call to this function that you must add to the top of the page:

protected void CommentFormSuccess(System.Web.UI.Control sender, object parameter)
{
CommunityServer.Blogs.Components.WeblogPost post = parameter as CommunityServer.Blogs.Components.WeblogPost;
if (post == null)
return;
if (!post.User.IsAnonymous)
return;
CommunityServer.Blogs.Controls.WeblogPostCommentForm form = sender as CommunityServer.Blogs.Controls.WeblogPostCommentForm;
if (form == null)
return;
System.Web.UI.WebControls.TextBox email = WeblogControlUtility.Instance().FindControl(form, "tbEmail") as System.Web.UI.WebControls.TextBox;
if (email == null)
return;
if (String.IsNullOrEmpty(email.Text))
return;
post.SetExtendedAttribute("AuthorEmail", email.Text);
WeblogPosts.Update(post);
}

The final step would be to add in the TextBox to prompt for the users email. What I did was wrap it up in a placeholder and only show it for non-RegisteredUsers.

<CSControl:PlaceHolder runat="server">
<DisplayConditions Operator="Not">
<CSControl:UserInRoleCondition runat="server" Role="Registered Users" UseAccessingUser="true" />
</DisplayConditions>
<ContentTemplate>
<div class="CommonFormFieldName">
Email:
<em>(<CSControl:ResourceControl runat="server" ResourceName="Optional" />)</em>
</div>
<div class="CommonFormField">
<asp:TextBox id="tbEmail" runat="server" Columns="60" />
<asp:RequiredFieldValidator id="emailValidator" runat="server" ControlToValidate="tbEmail" Cssclass="validationWarning">*</asp:RequiredFieldValidator>
</div>
</ContentTemplate>
</CSControl:PlaceHolder>

Now, when someone enters in their email address it will be stored in the ExtendedAttributes of the post.

Read on to see how I use this information.

Published Friday, May 11, 2007 1:30 PM

Comments

# re: Save Author's Email for Anonymous Blog Comments

Monday, May 14, 2007 10:07 AM by Bully
I'm an anonymous user with a gravatar!

# re: Save Author's Email for Anonymous Blog Comments

Monday, May 14, 2007 10:15 AM by Ben Tiedt

Cool use of the CustomAction!  You could also use a SubForm control to implement this behavior and prevent the double-save.

# Community Server Byte for May 15, 2007

Tuesday, May 15, 2007 10:21 AM by External Feeds

blog bits The CarKnee has been on a tear this week. He released three CS2007 controls, a control to add

# The CarKnee has been on a tear this week

Tuesday, May 15, 2007 10:49 AM by External Feeds

The CarKnee has been on a tear this week. He released three CS2007 controls, a control to add and save

# ExtendedAttribute Condition Control

Tuesday, May 15, 2007 7:51 PM by Sean Kearney's (CarKnee) Blog

I was working a new control for the CarKnee Bundle and was in need of a condition control within Community

# Identicons and Gravatars in Community Server thanks to CarKnee

Monday, June 18, 2007 8:40 PM by andrew @ grr, argh!

I've just gone through and added Identicons and Gravatars to my blog thanks to Sean Kearney's CarKnee

Powered by Community Server (Non-Commercial Edition), by Telligent Systems