Adding YouTube iframe code via the admin
2 posts by 2 authors in: Forums > CMS Builder
Last Post: April 12, 2013 (RSS)
By csdesign - April 11, 2013 - edited: April 11, 2013
Hello! I have what I hope is a super easy... and probably very obvious question. I've done this before but now I can't get it to work.
I want to enable the admin to be able to grab the iframe or embed code from youtube and then have that video appear on the page. I realize the problem is that the iframe code I enter is not being interpreted as code, but rather as text but I'm not sure how to fix it.
Here's an example iframe code:
<iframe width="480" height="360" src="http://www.youtube.com/embed/tys92pFGKOE?rel=0" frameborder="0" allowfullscreen></iframe>
I've entered that info the Video Embed field in the admin but it just appears on the page exactly as it does above.
Here's the code I was using in my page:
<?php echo htmlencode($horses_for_saleRecord['youtube_embed_code']) ?>
I tried variations like "urlencode" and even changed the field to WYSIWYG and entered it as html there. I also tried as a text box and checked "Disable auto-formatting (don't add break tags to content". that didn't work either. This is how it's showing up in the source code on the page once it's online. Right below it is one I entered manually into the php page. You can see the obvious difference between the two:
generated by cms:
<p><iframe width="480" height="360" src="http://www.youtube.com/embed/tys92pFGKOE?rel=0" frameborder="0" allowfullscreen=""></iframe></p>
entered by hand:
<iframe width="480" height="360" src="http://www.youtube.com/embed/tys92pFGKOE?rel=0" frameborder="0" allowfullscreen></iframe>
Some quick help would be GREATLY appreciated!! Thanks! Tina
By gregThomas - April 12, 2013
Hi Tina,
I don't think you should have to convert the characters into anything before you display them, it should be saved using the correct character set. The code you're currently using converts the charters into their HTML equivalent. For example the < character becomes <
I think you just need to display the data without converting it:
<?php echo $horses_for_saleRecord['youtube_embed_code'] ?>
if that doesn't work , you might have to decode the HTML characters into normal characters using the html_entity_decode function:
<?php echo html_entity_decode($horses_for_saleRecord['youtube_embed_code']) ?>
Let me know if you have any questions.
Thanks
Greg
PHP Programmer - interactivetools.com