Tinymce problem - extra paragraphs
im trying to use TinyMCE as part of a web form. Integration works fine, but once you submit the form, of course the data will be validated.
If validation evaluates to false, for example some other input has not been filled out, then of course I don't want the user to reenter all data. So i pass the Tinymce content back to the reloaded view.
The following problem occurs:
Content in Tinymce Textarea: test
Content in Tinymce after reload: <p>test</p>
So an extra paragraph is added as a wrapper each time.
I want Tinymce to treat the input, as if it was inserted into the html view, so that the plain text view would be allright, and no extra paragraphs are inserted.
How can I achieve this?
Thanks for your reply. That was just an example input, I definitely need an RTE, since I'm building some customized CMS functionality. I got it working now with html_entity_decode(), the html comes from a database, and yes, I do filter user input properly (basically CI does, but I tested to XSS on my own, just to make sure...). I'm not sure if I'm doing this the most elegant way...but the following seems to work fine for me:
JS Part:
<script type="text/javascript" src="<?php echo base_url();?>tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
$(document).ready(function(){
tinyMCE.init({
theme : "advanced",
mode : "textareas",
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
entity_encoding : "raw",
content_css : "<?php echo base_url();?>xcss/standard_tinymce.css",
});
});
</script>
Generate form textarea (the CI way):
echo form_textarea('content', html_entity_decode($content));
Thats it.
An input like:
<p><strong>test</strong></p><p>bla bla bla</p>
Would now be shown the following way in tinymce if it was stored in $content:
test
bla bla bla
And if you submit the form, then the post-data will be equal to $content again. And that is exactly the point where you should consider to check that post data for injections or XSS attacks, so please do not do it the same way, unless you keep track of what happens next...my solution probably is not very safe in ALL cases, in my case, this is fine, I assume, but if anyone knows bette开发者_JAVA技巧r, I'm definitely willing to learn more about that ;)
You can specifically tell TinyMCE not to wrap your content into a root tag by specifying
forced_root_block : false
in your TinyMCE init options.
However this is not recommended for various reasons, please read this entry in the FAQ: http://tinymce.moxiecode.com/wiki.php/TinyMCE_FAQ#TinyMCE_produce_BR_elements_on_enter.2Freturn_instead_of_P_elements.3F
Its quite simple.Add this to the tinymce init options
force_p_newlines : false
This is not possible due to the fact that tinymce (and all other rtes i know of) need to wrap text into block elements like p-tags or divs. This is neccessary in order to be able to style that text (one of the main functions of a rte). You might consider not to use a tinymce editor for such simple form inputs if you do not need html code there.
精彩评论