Part of the EllisLab Network
   
 
Storing HTML in MySQL
Posted: 27 August 2008 01:09 PM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  142
Joined  02-25-2007

Hey guys,

Have any of you encountered a need to store html in your database. I am tasked with using a wysiwig editor and then saving this information in the database. Once a user accesses a certain page, I need to output the previously stored HTML.

Best way to do this, with or without TinyMCE?

Thanks!

Profile
 
 
Posted: 27 August 2008 01:27 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  122
Joined  09-13-2007

This is very common, actually.  I have used FCKEditor, mainly.  I like it because it allowed me to specify what tags I want to allow. 

You still have to check the text before you store it.  In my most recent system I’m building, I’m stripping out everything except H, P, A, B, Strong, I, and EM tags.  There are CI and PHP functions that are useful in stripping out illegal chars… you can use all sorts of regex checks as well.

I haven’t used TinyMCE, but I would guess it’s similar to FCKEditor.  So to answer your question…. why not use both?  An editor AND backend processing.  You can’t be too safe.

While you’re at it, either use authentication, or a CAPTCHA to stop the form spammers.

Profile
 
 
Posted: 27 August 2008 01:55 PM   [ Ignore ]   [ # 2 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3153
Joined  06-11-2007

I have done a lot of work with TinyMCE and find it to be over engineered and slighly buggy. It could just be because we’re using an old version which im not allowed to upgrade, but im still not much of a fan.

Worth a try is Spaw which is a very simple and looks brilliant.

 Signature 

————————
Blog | Twitter | GitHub | BitBucket
————————-
PyroCMS - open source modular CMS built with CodeIgniter
PancakeApp - Simple, hosted invoicing/w project management

Profile
 
 
Posted: 27 August 2008 03:45 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  212
Joined  09-12-2007

I use TinyMCE. I also validate using the validation class. I am confused by your question. What is it that you are asking?
Is TinyMCE a decent wysiwyg editor? - sure, preferences may steer you to other editors, but you should be able to use it.
Is TinyMCE a decent way to validate the code? I doubt it. You should always validate it on the server.

If those aren’t your questions, please reply and clarify.

 Signature 

Voltamp Media
Web: PHP, MySQL, PERL, HTML, CSS, Python, Javascript
Linux: FreeBSD, OpenVPN, SMB, SVN, C, Shell

Profile
 
 
Posted: 28 August 2008 11:13 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  142
Joined  02-25-2007
Eric Cope - 27 August 2008 07:45 PM

Clarify question/quote]

My question is specifically how to validate HTML code.

Profile
 
 
Posted: 28 August 2008 11:56 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  212
Joined  09-12-2007

Are you looking to validate all HTML code, or a small subset? If its only a small subset, then a preg_match statement for each tag may be sufficient.  You could always integrate an external class like this:

http://twineproject.sourceforge.net/doc/phphtml.html

 Signature 

Voltamp Media
Web: PHP, MySQL, PERL, HTML, CSS, Python, Javascript
Linux: FreeBSD, OpenVPN, SMB, SVN, C, Shell

Profile