CodeIgniter Forums
HTML codes showing in viewpage HTML data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: HTML codes showing in viewpage HTML data (/showthread.php?tid=29261)



HTML codes showing in viewpage HTML data - El Forum - 04-04-2010

[eluser]mi6crazyheart[/eluser]
Hello Guys,
I'm a new to CI. Just using it in my project from last 2 months. I've a comment section in my project. Where any one can give comments. Every things are going perfect but when ever any one putting HTML content(image/videos) & then when those are showing back in the comment section... direct HTML codes are showing in the comment page rather than HTML content(image/videos).

ex: when i'm saving any "embed youtube video code" in the comment box & save that the out put comes as "raw Embed Video codes" rather than Youtube Video.....

I feel like it must be a minor thing but really can't understand where the fault has occurring. Plz, if any body have the solution reply me back as soon as possible.


HTML codes showing in viewpage HTML data - El Forum - 04-05-2010

[eluser]pickupman[/eluser]
Check the php.net site for the function html_entity_decode that might help point you in the right direction.


HTML codes showing in viewpage HTML data - El Forum - 04-06-2010

[eluser]Imran Tariq[/eluser]
Pikcupman is right. You should store it without decoding the original comments.


HTML codes showing in viewpage HTML data - El Forum - 04-27-2010

[eluser]mi6crazyheart[/eluser]
I used that "html_entity_decode" but now all the EMBED video codes are getting print rather than the original video. I also tried to use "htmlspecialchars_decode" but it also not doing the same thing(showing the codes but not the original video)

My Controller :
Code:
$this->form_validation->set_rules('CommentMessage', 'Comment', 'htmlspecialchars_decode|trim|required|min_length[2]|max_length[5000]|xss_clean');

My Model :
Code:
$CommentMsg = auto_link(auto_typography($this->input->post('CommentMessage')),'both', TRUE);
$this->db->set('CommentContent', $CommentMsg);



HTML codes showing in viewpage HTML data - El Forum - 04-27-2010

[eluser]pickupman[/eluser]
You will need to use a combo of htmlentities in your callback to save the data in the db as non html characters. Then when you want to display it back on a page you will then use html_entitiy_decode the string to convert it back to html.


HTML codes showing in viewpage HTML data - El Forum - 04-28-2010

[eluser]mi6crazyheart[/eluser]
@pickupman
Thanks a lot. Your suggestion worked....... :coolsmile: