Note that there are some explanatory texts on larger screens.

plurals
  1. POTinymce problem - extra paragraphs
    text
    copied!<p>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.</p> <p>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.</p> <p>The following problem occurs:</p> <p>Content in Tinymce Textarea: test</p> <p>Content in Tinymce after reload: <code>&lt;p&gt;test&lt;/p&gt;</code></p> <p>So an extra paragraph is added as a wrapper each time.</p> <p>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.</p> <p>How can I achieve this?</p> <hr> <p>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:</p> <p>JS Part:</p> <pre><code>&lt;script type="text/javascript" src="&lt;?php echo base_url();?&gt;tinymce/jscripts/tiny_mce/tiny_mce.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(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 : "&lt;?php echo base_url();?&gt;xcss/standard_tinymce.css", }); }); &lt;/script&gt; </code></pre> <p>Generate form textarea (the CI way):</p> <pre><code>echo form_textarea('content', html_entity_decode($content)); </code></pre> <p>Thats it.</p> <p>An input like:</p> <pre><code>&lt;p&gt;&lt;strong&gt;test&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;bla bla bla&lt;/p&gt; </code></pre> <p>Would now be shown the following way in tinymce if it was stored in $content:</p> <p><strong>test</strong></p> <p>bla bla bla</p> <hr> <p>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 better, I'm definitely willing to learn more about that ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload