Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: DD Mega Menu and "safe mail" script causing issue?

  1. #1
    Join Date
    Dec 2015
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question DD Mega Menu and "safe mail" script causing issue?

    Script: DD Mega Menu
    http://www.dynamicdrive.com/dynamici...ddmegamenu.htm

    I am nearly complete with getting my new Navigation Bar set up to deploy on my website. However, there's one thing I am having an issue with (and if the method I am using currently completely sucks, and there's some other solution to give me similar results - I am all ears!)

    Right now, we use a script to help prevent some spam from being sent to our email addresses:

    Code:
    <!--
    function safemail(name, domain, display) {
    displayed=(typeof(display)=="undefined") ? name+"@"+domain : display
    document.write('<a href=mailto:' + name + '@' + domain + '>' + displayed + '</a>');
    }
    // -->
    We call that safemail.js

    So within our menu we have some links you can click on to send emails (you can see the current at https://w4bfb.org/index_w4bfb.php under "Contact" > "Email Contacts" at the far right). we simply put the following code currently:

    Code:
    <li><script type="text/javascript">safemail("board","w4bfb.org","* All Board Members")</script></li>
    However, when I add that to the new DD Mega Menu I am setting up, the results are seen on https://w4bfb.org/index_new.php - it does some weird redirect or something and pretty much and shows only that link to send the email. The source, you can see, has the whole website there though.

    Is there something obvious I can do to change / fix this, or maybe another anti-spam method you can recommend that won't cause issues with the new menu?


    Please ignore any SSL errors you may see - the webhost is rolling out new certs and stuff, so I am trying to get this project finished up so I can properly troubleshoot all they are doing

    [Edit]

    I have tried different variables in the js and it did the same thing, so I do not believe it has to do with the actual variables used. Here is the code of the chunk causing issues:

    Click image for larger version. 

Name:	screenshot_code.jpg 
Views:	173 
Size:	8.9 KB 
ID:	5765
    Last edited by neocharles; 12-21-2015 at 10:35 PM. Reason: Resolved!

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I see you have a PHP page so how about a PHP function? Here's one I use quite a bit - it converts random characters to HTML character codes;
    Code:
    function getObfuscatedEmailAddress($email) {
        	$alwaysEncode = array('.', ':', '@');
        	$result = '';
        	for ($i = 0; $i < strlen($email); $i++) { // Encode string using oct and hex character codes
                	if (in_array($email[$i], $alwaysEncode) || mt_rand(1, 100) < 25) { // Encode 25% of characters including several that always should be encoded
        	    	    	if (mt_rand(0, 1)) { 
        	    	    	    	$result .= '&#' . ord($email[$i]) . ';';
        	    	    	    	} else { 
        	    	    	    	$result .= '&#x' . dechex(ord($email[$i])) . ';'; }
        	    	    	} else { 
        	    	    	$result .= $email[$i]; }
            	}
        	return $result;
        	}
    
    function protectEmail($email, $text = null, $params = array()) {
        	if (!is_array($params)) { $params = array(); }
        	if (!isset($params['rel'])) { $params['rel'] = 'nofollow'; }
        	$neverEncode = array('.', '@', '+'); // Don't encode - not fully supported by IE & Chrome
        	$urlEncodedEmail = '';
        	for ($i = 0; $i < strlen($email); $i++) {
        	    	if (!in_array($email[$i], $neverEncode) && mt_rand(1, 100) < 25) { // Encode 25% of characters
        	    	    	$charCode = ord($email[$i]);
        	    	    	$urlEncodedEmail .= '%';
        	    	    	$urlEncodedEmail .= dechex(($charCode >> 4) & 0xF);
        	    	    	$urlEncodedEmail .= dechex($charCode & 0xF);
        	    	    	} else {
        	    	    	$urlEncodedEmail .= $email[$i];
        	    	    	}
        	    	}
        	$obfuscatedEmail = getObfuscatedEmailAddress($email);
        	$obfuscatedEmailUrl = getObfuscatedEmailAddress('mailto:' . $urlEncodedEmail);
        	$link = '<a href="' . $obfuscatedEmailUrl . '"';
        	foreach ($params as $param => $value) {
        	    	$link .= ' ' . $param . '="' . htmlspecialchars($value). '"';
        	    	}
        	$link .= '>' . $text . '</a>';
        	return $link;
        	}
    usage
    Code:
    <?php echo protectEmail('me@email.com', 'Email Me'); ?>
    Last edited by Beverleyh; 12-21-2015 at 09:56 PM. Reason: Separate code blocks
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Dec 2015
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hmmm, I can give it a shot, but when I try to use it (in quickly testing it), it seems to break the rendering of other parts of the website.

    My other option is to finally break down and create contact forms. Which probably is the better option.

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    when I try to use it (in quickly testing it), it seems to break the rendering of other parts of the website.
    Shouldnt do, but I'll separate the code to make usage clearer. How are you applying it? It's a PHP function so firstly, it should go right at the top of the page (or ideally in a functions include file) in PHP tags; <?php at the start and ?> at the end. It should only appear once in the page/file.

    Then when you want to use it, just do <?php echo protectEmail('me@email.com', 'Email Me'); ?>, unless it's within more PHP code, in which case you omit the start and end PHP tags.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. #5
    Join Date
    Dec 2015
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    Shouldnt do, but I'll separate the code to make usage clearer. How are you applying it? It's a PHP function so firstly, it should go right at the top of the page (or ideally in a functions include file) in PHP tags; <?php at the start and ?> at the end. It should only appear once in the page/file.

    Then when you want to use it, just do <?php echo protectEmail('me@email.com', 'Email Me'); ?>, unless it's within more PHP code, in which case you omit the start and end PHP tags.
    I've tried a few ways of including it ... but it seems to only load the header (you can see it live now). Not sure what is causing that at the moment. (I'll admit - I am definitely not an expert whatsoever. This has been a great learning experience for me taking over the website)

    I have created a file, safemail.php, and within it I have
    Code:
    <?php
    function protectEmail($emailaddress, $text = null, $params = array()) {
        	if (!is_array($params)) { $params = array(); }
        	if (!isset($params['rel'])) { $params['rel'] = 'nofollow'; }
        	$neverEncode = array('.', '@', '+'); // Don't encode - not fully supported by IE & Chrome
        	$urlEncodedEmail = '';
        	for ($i = 0; $i < strlen($emailaddress); $i++) {
        	    	if (!in_array($emailaddress[$i], $neverEncode) && mt_rand(1, 100) < 25) { // Encode 25% of characters
        	    	    	$charCode = ord($emailaddress[$i]);
        	    	    	$urlEncodedEmail .= '%';
        	    	    	$urlEncodedEmail .= dechex(($charCode >> 4) & 0xF);
        	    	    	$urlEncodedEmail .= dechex($charCode & 0xF);
        	    	    	} else {
        	    	    	$urlEncodedEmail .= $emailaddress[$i];
        	    	    	}
        	    	}
        	$obfuscatedEmail = getObfuscatedEmailAddress($emailaddress);
        	$obfuscatedEmailUrl = getObfuscatedEmailAddress('mailto:' . $urlEncodedEmail);
        	$link = '<a href="' . $obfuscatedEmailUrl . '"';
        	foreach ($params as $param => $value) {
        	    	$link .= ' ' . $param . '="' . htmlspecialchars($value). '"';
        	    	}
        	$link .= '>' . $text . '</a>';
        	return $link;
        	} 
    ?>
    Then in the index_new.php I have
    Code:
    <?php include './newnavbar/newnavbar.php; './ssi/safemail.php'; ?>
    Then within the menu bar item I have
    Code:
    <li><?php echo protectEmail('board@w4bfb.org', 'Board Members'); ?></li>

  6. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    My bad - there are 2 functions and I hadn't copied the first one. I've modified the code now so that both are included
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  7. #7
    Join Date
    Dec 2015
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Updated, but still have the same result. Even when you hover over Contact Us > Email Contacts, that window is blank (even though there should be things in there). Something's not jiving right somewhere

  8. #8
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Ack! I'm a bit stuck here because I'm on iPhone/iPad until I get back in the office in January so unfortunately I can't look any deeper for you
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  9. #9
    Join Date
    Dec 2015
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    Ack! I'm a bit stuck here because I'm on iPhone/iPad until I get back in the office in January so unfortunately I can't look any deeper for you
    It's not a problem. Looking at the source, it pretty much seems to go blank right after the <li> where it should begin the <?php stuff

  10. #10
    Join Date
    Dec 2015
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Interestingly, if I add the code you provided to the top of newnavbar.php it seems to execute properly... I think.

    Only downside I see at a glance right now is it has the down arrow next to the email address, since it uses the rel="nofollow".
    Last edited by neocharles; 12-21-2015 at 10:24 PM.

Similar Threads

  1. Stick Responsive CSS3 Dropdown with lyouts Mega Menu ala Amazon "Shop by Department"
    By DD-Newbie in forum Looking for such a script or service
    Replies: 1
    Last Post: 02-20-2015, 08:52 PM
  2. Replies: 1
    Last Post: 01-12-2009, 11:31 PM
  3. Anylink drop-down menu target="" causing problems
    By Spinethetic in forum Dynamic Drive scripts help
    Replies: 8
    Last Post: 06-17-2008, 08:15 PM
  4. "e-mail this page" script
    By loifinc in forum JavaScript
    Replies: 8
    Last Post: 07-27-2007, 03:40 AM
  5. "e-mail this page" script
    By loifinc in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 02-07-2005, 08:53 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •