Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

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

SS Removing Closing <iframe> Tag From TextField


Reply

15 Posts   4654 Views

Avatar
swaiba

27 November 2010 at 8:47am Forum Moderator, 1796 Posts

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

Avatar
neilcreagh

30 November 2010 at 12:23pm Community Member, 94 Posts

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.

Avatar
swaiba

30 November 2010 at 9:31pm Forum Moderator, 1796 Posts

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.

Avatar
neilcreagh

30 November 2010 at 11:42pm Community Member, 94 Posts

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

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

Avatar
Chris Hope

9 May 2011 at 11:19am Community Member, 18 Posts

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();
}

Avatar
ttyl

22 November 2011 at 7:27am (Last edited: 22 November 2011 7:46am), Community Member, 114 Posts

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.

Avatar
LePhil

3 August 2012 at 3:43am Community Member, 3 Posts

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.