Reputation: 45124
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
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
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
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
Upvotes: 4
Reputation: 1931
JFactory::getEditor()
is deprecated. You should use JEditor::getInstance()
since 12.3
Upvotes: 2