Techie
Techie

Reputation: 45124

How to make Joomla 3.0 rich text editor allow HTML?

In Joomla 2.5 I use below code generate a rich text editor and it allows me to enter HTML and save it in the database. Code is below.

<?php 
$editor = & JFactory::getEditor();
$params = array('smilies'=> '0' ,'style'  => '0' ,'layer'  => '0' ,'table'  => '0' ,'clear_entities'=>'0');
echo $editor->display('description',$description  , 550, 400, 60, 20, false, $params); 
?>

But in the Joomla 3.0 I use the same code but rich text editor does not allow me to enter HTML. Editor in the Article Manager rich text editor allows me to enter HTML. Why does this editor does not?

How can I fix this? What extra parameters should be passed to allow rich text editor to allow HTML?

Upvotes: 4

Views: 3381

Answers (4)

xavip
xavip

Reputation: 553

In Joomla 3.6 I get this error

Use of undefined constant JREQUEST_ALLOWHTML - assumed 'JREQUEST_ALLOWHTML'.

I arrived to the conclusion that the best way to retrieve html formatted text in Joomla is this:

$html = JComponentHelper::filterText(JFactory::getApplication()->input->post->get($var_name, $default_value, 'raw'));

Hope this helps

Upvotes: 0

Tharanga
Tharanga

Reputation: 2767

when you are using XML form structure you can use 'editor' form field type. In that case for allowing HTML tags you have to use the attribute "filter='safehtml'" to allow saving the content with html tags.

eg:

<field
                name="event_desc"
                type="editor"
                editor="tinymce"
                width="400"
                height="100"
                label="COM_YOURCOMPONENT_FIELD_LABEL"
                description="COM_YOURCOMPONENT_FIELD_DESC"
                cols="30"
                rows="5"
                class=""
                default=""
                filter="safehtml"
                />

Hope this will save some ones time. :) Happy coding!

Upvotes: 1

Techie
Techie

Reputation: 45124

HINT for your JModel:

Be aware that JRequest::GET by default filters all HTML-code down to plain text, which might not be very useful when using the editor. To store HTML-code within your model class you MUST explicitely request HTML-Code from the JRequest-Object, otherwise all HTML will be stripped.

JRequest::getVar( 'yourfieldname', '', 'post', 'string', JREQUEST_ALLOWHTML );

JREQUEST_ALLOWHTML is the key point to remember. Given that

  • JREQUEST_NOTRIM - prevents trimming of whitespace
  • JREQUEST_ALLOWRAW - bypasses filtering
  • JREQUEST_ALLOWHTML - allows most HTML. If this is not passed in, HTML is stripped out by default.

Upvotes: 4

McRui
McRui

Reputation: 1931

JFactory::getEditor() is deprecated. You should use JEditor::getInstance() since 12.3

Upvotes: 2

Related Questions