Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » SS Removing Closing <iframe> Tag From TextField

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 4509 Views
  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: SS Removing Closing <iframe> Tag From TextField Link to this post

    maybe place some code in the Page onbeforewrite that does a search replace to enter the space on $this->MyHTMLText

  • neilcreagh
    Avatar
    Community Member
    90 Posts

    Re: SS Removing Closing <iframe> Tag From TextField Link to this post

    Thanks, but that's not ideal because the code will vary depending on each video setting, and obviously I can't do a find & replace just on a self closing tag or it would affect other code.

  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: SS Removing Closing <iframe> Tag From TextField Link to this post

    I'm not recommending a blanket acceptance of self closing tags - a regular expression matching something like "<iframe*vimeo*></iframe>" and you'd be able to identify the specific self-closing tags that you want to keep.

  • neilcreagh
    Avatar
    Community Member
    90 Posts

    Re: SS Removing Closing <iframe> Tag From TextField Link to this post

    Ah, I misunderstood. That works a treat, thanks!

    function onBeforeWrite() {
    $this->VimeoCode1 = str_replace("></iframe>", "> </iframe>", $this->VimeoCode1);
    parent::onBeforeWrite();
    }

  • Chris Hope
    Avatar
    Community Member
    18 Posts

    Re: SS Removing Closing <iframe> Tag From TextField Link to this post

    I've found that doing this:

    function onBeforeWrite() {
    $this->Content = str_replace("></iframe>", "> </iframe>", $this->Content);
    parent::onBeforeWrite();
    }

    doesn't work because the content has already been loaded into the object using domdocument so it's already collapsed the iframe. I've used this regexp instead:

    function onBeforeWrite() {
    $this->Content = preg_replace('|<iframe(.*)/>|Uims', '<iframe\\1> </iframe>', $this->Content);
    parent::onBeforeWrite();
    }

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: SS Removing Closing <iframe> Tag From TextField Link to this post

    I just want to confirm Chris' solution works, thanks!

    Spoke too soon, didn't help. Instead I'm just putting an '&nbsp;' inside the iframe tags...not a great solution.

  • LePhil
    Avatar
    Community Member
    3 Posts

    Re: SS Removing Closing <iframe> Tag From TextField Link to this post

    If someone's still having the same problem: I tried Chris's solution with ttyl's input - didn't work. It still removes the closing tag.

    What did it for me (2.4.7) was the post from dendeffe on Page 1 of this thread.

    Change the field form a HTMLText to a Text and use $myfield.RAW in the template. That's it.

    4509 Views
Page: 1 2
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.