WYSIWYG Content Editing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
codemonkey
Forum Newbie
Posts: 6
Joined: Thu Oct 29, 2009 6:06 pm

WYSIWYG Content Editing

Post by codemonkey »

Hello,

I have 2 pages, a main "blog" page, and a "content management" page. The content management page is basically a form where I can enter the blog post, and my php script writes the data to a MySQL database. The main page then has a php script to read this information from the database and display it on the website. Works great to post text to my website, but that's about it.

I want to have the ability to edit the formatting of my text, and insert images just like I can in this forum post. So I got an opensource WYSIWYG editor, and after applying it to the textarea of the form on my content editing page, i can do just that. But nothing happens with it.

So my problem is, I (think I) need to be able to take the html that is generated by the WYSIWYG text editor, and save it to the MySQL database. Then I need to be able to retrieve it and display my blog post as it was formatted originally.

How can I do this? I've searched for hours trying to find a simple opensource code and all I can find is entire content management systems! All I want is this one page to be editible using HTML!

Thank-you,
-Jonathan
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: WYSIWYG Content Editing

Post by Christopher »

FCKeditor and TinyMCE are two often used editors.
(#10850)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: WYSIWYG Content Editing

Post by superdezign »

"Nothing happens with it"?
Basically, get a WYSIWYG, and treat your textarea the same as it already is when submitting. WYSIWYGs typically hide the textarea and apply any changes to the HTML to the textarea as well, giving you raw HTML to add to your database.

I've recently tried OpenWYSIWYG. Not that I'd recommend it in terms of functionality, as all WYSIWYGs have very similar downfalls. But it's integration is simple, so I'd recommend it for that.
codemonkey
Forum Newbie
Posts: 6
Joined: Thu Oct 29, 2009 6:06 pm

Re: WYSIWYG Content Editing

Post by codemonkey »

superdezign wrote:"Nothing happens with it"?
Basically, get a WYSIWYG, and treat your textarea the same as it already is when submitting. WYSIWYGs typically hide the textarea and apply any changes to the HTML to the textarea as well, giving you raw HTML to add to your database.
Thank-you for your reply, I wasn't clear when I said "nothing happens". The editor changes the formatting of the text properly while using the form, but when it is submitted all formatting is lost and the main page only displays the unformatted text.

I must have problems within my code, I happen to be using openWYSIWYG (left it out of below code for simplicity).

On my "manage content" page I have this code to submit the "message" to my database:

Code: Select all

if(isset($_POST['submit']) ) {
 
    $message = mysql_real_escape_string($_POST['message']);
 
    $sql = "INSERT INTO Blog (Post) VALUES ('$message')"; 
    
    mysql_query($sql) or die(mysql_error());
    }
On my "main page" I have this code to retreive the message and display the post:

Code: Select all

   // Request the text of the messages
    $result = mysql_query("SELECT * FROM Blog WHERE 1 LIMIT 0,10");
 
    while ( $row = mysql_fetch_array($result) ) {
        echo("<P>" . $row["Post"] . "</P>");
        }
What I want is for the message to be displayed however the user decides to format it using the WYSIWYG. It seems as though the HTML formatting from the WYSIWYG is getting ignored.

I'm guessing that this has something to do with my PHP script ignoring the HTML tags and just taking the text?

Thank-you for your help, it is greatly appreciated.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: WYSIWYG Content Editing

Post by superdezign »

Output the $_POST array when submitting the form to ensure that $_POST['message'] is in fact what you are after. It is possible that your WYSIWYG creates more than one textarea, though I doubt it.
Post Reply