Question

I'm building a SharePoint (MOSS) publishing site for employee information on my company website. I have an employee content type and am using the Contact E-Mail Address site column to store an employee's email address.

Want I'd like is the ability to encode email addresses at runtime to prevent the real email address from being harvested by spammers. This would be decoded when a user clicks the email hyperlink e.g. the following HTML would be sent to the browser:

<a href="javascript:sendEmail('5237952A6F67618E407373772E6063212E6175')">Email Jonny</a>

I already have the javascript methods for encoding/decoding a text value from the meaningless string above, but am not too sure as to how to approach this with SharePoint in mind. I'm thinking a custom control and/or custom J-Query?

Any help would be much appreciated!

Jonny

Was it helpful?

Solution

In the case that you are unable to put the users into AD, a custom field control will give you the ability to include the custom rendering (jquery) you require as well as the ability to enter the data as "normal" text.

The custom field, once defined "just works" wherever you need to display the field.

Given you are thinking of using JQuery, the issue then becomes one of making sure the jquery library is correctly linked whenever you need to us a field of this type.

OTHER TIPS

If you make those employees members of the site, SharePoint takes care of this issue.

You can send emails to them, but the email address will only be used at send time, when you add a button to email someone, it will not show the email address, its handled at the backend.

SPUtility.SendEmail(SPContext.Current.Web, false, false,
[SPUser.Email][1], "E-mail title",
"E-mail body");

alt text
(source: msdn.com)

Two more options/approaches you can try:

(1) implement a custom TextField control, inheriting from Microsoft.SharePoint.WebControls.TextField and override RenderFieldForDisplay

Then in code - encode the field for display.

Add this control to safecontrols and use this in place of the normal TextField in the pagelayout.

(2) use the existing TextField control, but inject a button [Encode] using jQuery next to the TextField in editmode.

Use the JavaScript encode method to encode what the user has typed into an encoded value, replacing the existing TextField value. Which they can then save to into SharePoint.


I'd rate the approaches based on your deployment scenario - Nat's one is the cleanest but probably more involved for deploying, and the jQuery-only one seems very hackish but easy on deployment. The override TextField approach would probably sit somewhere in the middle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top