5
votes

I'm using TinyMce textarea editor and have a problem. As you probably know Tinymce transforms a standard html textarea into a rich text editor.

On our 'edit listing' page we call up some text from our db for the user to edit (previously in a standard textarea, now in the tinymce textarea.

Previously the standard textarea would preserve linebreaks and the user would get several paragraphs of text in the text area, now with tinyMCE they get a huge chunk of text with no linebreaks. (I have pasted an example of an entry in our db below - as you can see it has line breaks in it by tinymce seems to be ignoring them when it displays them in the editor).

Just to clarify my issue is now that tinymce is stripping something when I submit the form, it's that when I pull text (that contains line breaks) from the db and populate the tinymce textarea with that data (for the user to edit) in the tinymce textarea - the text appears (in the tinymce textarea) as one massive chunk of text with my paragraphs (whereas in a standard textarea it is nicely formatted with linebreaks)

Any help on how to resolve this would be greatly appreciated - do I need to use some sort of populate() type function to put the text in, or maybe I need to replace all the linebreaks with a different special character that tinyMCE will recognise as a line break and preserve?..

Thanks in advance. Nick

example from db:


Here is line one

Here is line two

And here is line three

Which appears in tinymce as:


Here is line one Here is line two And here is line three

1
It looks like you are saving the data without the line breaks. Make sure that 1) you are saving your tags (the editor is not removing any <p> or <br/>) and 2) make sure that the encoding is correct.Zuzlx
Thanks for your reply Zuzix. 1) the editor is not removing any tags it's just removing the line breaks (or someother special character that creates a linebreak/carridge-return) 2) when it comes to encoding - how would i check it is correct, and where does one check that (is that in IIS, my database (mysql), server (adobe coldfusion) or in the tinymce config? Thanks so much for your help. Nickhappysailingdude
Copy what's in the DB, save it in a text file with extension .html. View it in the browser. I'm trying to figure out whether it is your text or the editor. Another thing you can do is replace the editor with a div and dump the content. Is the content formatted correctly?Zuzlx

1 Answers

0
votes

I faced a similar a problem, a while back and had questions just like yours. Also I finally ended up on SE just like you. Anyway, I think I have the solution to your problem. If you are using PHP as your server side language, then you should use nl2br() PHP function. Suppose you have stored your content fetched from the database in a php variable. Something like this:

$content = $row['content'];

Now when displaying it on to your screen, use the nl2br() function.

echo nl2br("<p>".$content."<p>");

Now, this part inside () depends on how you want to output the data. And I will leave it to you to figure that part out.

Hope this helps.