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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

SS Removing Closing <iframe> Tag From TextField


Go to End


15 Posts   7521 Views

Avatar
swaiba

Forum Moderator, 1899 Posts

27 November 2010 at 8:47am

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

Avatar
neilcreagh

Community Member, 136 Posts

30 November 2010 at 12:23pm

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

Forum Moderator, 1899 Posts

30 November 2010 at 9:31pm

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

Community Member, 136 Posts

30 November 2010 at 11:42pm

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

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

Avatar
Chris Hope

Community Member, 18 Posts

9 May 2011 at 11:19am

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

Community Member, 114 Posts

22 November 2011 at 7:27am

Edited: 22/11/2011 7:46am

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

Community Member, 3 Posts

3 August 2012 at 3:43am

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.

Go to Top