ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Can't get emails to encode

July 15, 2012 4:31pm

Subscribe [1]
  • #1 / Jul 15, 2012 4:31pm

    roryrabbitfield

    320 posts

    I want encoded emails, but i’m having probelms (want emails protected by javascript so spammers have a harder time getting them).

    I need to display email links 2 ways:

    1.
    I have a channel that has an email address in a wygwam (third-party) field. that channel DOES have the prefernce set to turn urls & emails into links automatically. but, the email address is not being encoded. What could be wrong here? Should be pretty straightforward, right? I am using a channel tag, with my custom field’s name inside curly brackets to output the content of the wygwam field. The email address shows up as a link that is clickable, but when i view the source code for the page, the email address is not encoded, it is just given out in plain text.

    2.
    In another place, i want to hard-code the email address into a template. how do i get that email address to encode? I tried this:

    <a href="mailto:{encode=%[email protected]%27}" class="envelope">mailtest</a>

    but it doesn’t work, it shows the encoded javascript on the page. I need to use a mailto link in an anchor tag here because I am actually using CSS to just show an image instead of the text ‘mailtest’. Notice I am using single quotes inside the encode thing, and double quotes outside it, as the encloser for the mailto part.

    So, how do I solve both these problems?

    Using EE v2.5.2 - Build Date: 20120606.

  • #2 / Jul 15, 2012 8:34pm

    The encode function provides the complete <a> tag surrounded by a parent .

    Instead of this:

    <a href="mailto:{encode=%[email protected]%27}" class="envelope">mailtest</a>

    Use this:

    {encode="[email protected]" title="mailtest"}

    Which produces:

    <span data-eeencemail_eglhdnmgfq="1">
    <a href="mailto:[email protected]">mailtest</a>
    </span>

    You can’t add a class to the function, so to style that specific field you’ll need to wrap it up and style the parent element, something like:

    {encode="[email protected]" title="mailtest"}
  • #3 / Jul 15, 2012 9:43pm

    roryrabbitfield

    320 posts

    Thanks Michael. I can’t get my encoding to work with the style I need, so I am going to ditch the style and go with just showing a regular text link. But thanks for the info, that is useful to know.

    Regarding the other half of my request… if anyone has any thoughts on why my channel’s custom field output isn’t encoding an email address even though its pref is set to automatically encode urls & emails, that one i really do need help with! (I am talking about issue #1 of in my original question.)

    thanks,
    rory

  • #4 / Jul 17, 2012 12:19pm

    Kevin Smith

    4784 posts

    Hi Rory,

    The exception for the preference in EE to turn URLs and email addresses into links is for fields like Wygwam and the Rich Text Editor, where the user editing the content actually has the option to make a link out of any text they like using the editor’s visual tools. Have you tried just using a standard text field instead?

  • #5 / Jul 18, 2012 10:26pm

    roryrabbitfield

    320 posts

    I didn’t realize that the encoding doesn’t work in wygwam fields. I was able to switch to a regular text input in this case, so i’m all set. thanks!

  • #6 / Jul 19, 2012 3:56pm

    Kevin Smith

    4784 posts

    Glad I could help, Rory! Have a good one.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases