views:

589

answers:

3

Hello,

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

+2  A: 
Ric Tokyo
Hi Ric,Great suggestion, however I don't think we can go with the membership option. We also want to display information about past employees (current/past is enabled by a checkbox on the content type). Past employees would not be members.Any other ideas?
Jonny
@Nat nailed it I think
Ric Tokyo
+2  A: 

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.

Nat
Hi Nat, thanks very much for your comment. A custom field control sounds perfect for my requirements. I was not previously aware of this option!
Jonny
A: 

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.

John Liu