How to hide / encrypt CCK Email field with JS against spammer

I got headche while searching for a filter to encrypt/hide email cck field to protect email addresses from spambots. I have installed , deinstalled, activated-deactivated rearranged input filters with both invisimail and spamspan but no luck! Finally I decide to change code in email.module. It works! Go and open "sites/all/modules/email/email.module" and find the line 115 like this:

/**
 * Theme function for 'default' email field formatter.
 */
function theme_email_formatter_default($element) {
  return !empty($element['#item']['safe']) ? '<a href="mailto:'. $element['#item']['email'] .'">'. $element['#item']['safe'] .'</a>' : '';
}

replace line 118-120 with following

function theme_email_formatter_default($element) {

$str = trim( $element['#item']['safe'] );
if( !$str ) return;

for($i=strlen($str)-1; $i>-1; $i--) { $arr[] = "'".substr($str, $i, 1)."'"; }

$js_arr2str = implode(", ", $arr);

return <<<hrd
	<script language="javascript" type="text/javascript">
		var em_real = [$js_arr2str], em_safe_str = "";
		for(i=em_real.length-1; i>-1; i--){ em_safe_str += em_real[i];	}
		document.write('<a hr'+'ef="mai'+'lto:'+em_safe_str+'">'+em_safe_str+'</a>');
	</script>
hrd;

}

Comments

With multiple email

With multiple email addresses, would be a problem? I mean multiple declaration of "em_real".

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Use <pre> all your html php come here </pre> for your code
  • Allowed HTML tags: <a> <b> <pre> <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <style><img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

CafeWebmaster.com(CW) is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.