Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » email spam protection rewrite

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 351 Views
  • innoweb
    Avatar
    Community Member
    5 Posts

    email spam protection rewrite Link to this post

    Hi guys,

    I have built a module that replaces all email addresses on the website with a link to a contact form for spam protection.

    <a href="/link/to/contact/form/with/encoded/email/address" title="E-Mail not shown if javascript is disabled." rel="nofollow" class="contact replacetext">[E-Mail via form]</a>


    This link is then reversed to a mailto-link using javascript.

    In SS2.4 and 3 I used to do the replacement in the forTemplate() method of the DBField classes (Varchar, Text, HTMLVarchar, HTMLText). This way all emails shown on the website were replaced and I was still able to use $Field.RAW where the email address had to stay.
    Now in SS3.1 the RAW doesn't work anymore, meaning that the email addresses still get re-written.

    Does anyone have an idea why RAW does behave this way in SS3.1?
    Can anyone give me a hint where to do the rewrite other than the forTemplate() method of the DBField classes? Is there a way to somehow inject something like a rewrite_hash_links or something similar to shortcodes?

    Thank you very much!

  • innoweb
    Avatar
    Community Member
    5 Posts

    Re: email spam protection rewrite Link to this post

    bump. anyone?

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: email spam protection rewrite Link to this post

    I assume because the default casting has changed from Text to HTMLText. You can register your own parser to alter the object - http://api.silverstripe.org/3.1/class-TextParser.html

  • innoweb
    Avatar
    Community Member
    5 Posts

    Re: email spam protection rewrite Link to this post

    Hi Will,
    Thanks for your reply.
    Unfortunately this is not the solution I'm after. First you would need to call the parser in the templates for every field, second it would only work for Text/HTMLText fields and not for Varchar/HTMLVarchar.
    What I had before SS3.1 was a solution where EVERY email address anywhere on the website was replaced (apart from hard coded ones in the templates).
    I agree that this is probably because of the default casting. But it is still strange that RAW results in the value being converted to xml anyway. But that's probably because the surrounding template is converted to xml by the default casting later on. Is there a way to prevent this from happening in order to get the RAW to be really RAW?
    Or maybe there is a way to change the behavior not of the db fields but the template parsing?
    Thank you very much.

    351 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.