0

When we enter properly formatted HTML into the RTE via the CP, the <p> tags are present. But when we use the {exp:channel:form ...} we lose all the <p> tags but retain all other tags. We're using Textarea (Rich Text) fields because we need the RTE on our custom dashboard.

I tested the {exp:channel:entries ...} and the <p> tags were properly retained.

So what could be causing this? How can we fix it? We need the channel form to output the proper tags because we have a live preview of what's in the populated textarea elements.


Update:

When using {field:my_channel_field} the <p> tags are retained, but the RTE isn't created. It's just a textarea with html/text.


Update 2:

I did some digging and found that in the SQL tables there are no <p> tags, meaning that they're inserted when the data is called.

For instance this is what's actually in the Database

<h3>Lorem nascetur </h3> Porttitor. Integer nunc. Hac ultricies velit magnis. Nunc est, tortor proin? 

And this what is output when using {exp:channel:entries ...}:

<h3>Lorem nascetur </h3>

<p> Porttitor. Integer nunc. Hac ultricies velit magnis. Nunc est, tortor proin?</p>

So at some point the <p> tags are being injected into the document, and I want to know how can I force this so they are in the RTE when the user goes to edit them within an {exp:channel:form ...} loop?


Update 3:

I found these in /system/expressionengine/modules/rte/libraries/Rte_lib.php on lines 445 to 446

// Strip paragraph tags
$data = preg_replace("#<(/)?pre[^>]*?>#i", "<$1pre>", $data);
$data = preg_replace("#<p>|<p(?!re)[^>]*?".">|</p>#i", "",  preg_replace("#<\/p><p(?!re)[^>]*?".">#i", "\n", $data));

and

if (stristr($str, '<p') !== FALSE)
{
    $str = preg_replace("#<(/)?pre[^>]*?>#i", "<$1pre>", $str);
    $str = preg_replace("#<p>|<p(?!re)[^>]*?".">|</p>#i", "",  preg_replace("#<\/p><p(?!re)[^>]*?".">#i", "\n", $str));
}

in /system/expressionengine/libraries/EE_Typography.php.

Commenting them out didn't seem to solve the problem


Update 4:

I tested my theory more completely by simply doing a {exp:channel:entries ...} and {exp:channel:form ..} on a blank template with nothing other than a field.

When output, the channel:form actually outputs HTML tags (<h3> from update 2 above) that never get rendered, and the channel:entries outputs the correct HTML and does get rendered. See picture:

Example of channel:form output

0

1 Answer 1

1

After much consternation I tried commenting out the Strip paragraph tags section of the save_field() function from above again, but tested it more thoroughly and it works. It keeps the tags on submission/repopulation through channel:form. This might cause bugs down the line, but it'll do for now.

/system/expressionengine/modules/rte/libraries/Rte_lib.php

lines 445 to 447.

// Strip paragraph tags
/*
$data = preg_replace("#<(/)?pre[^>]*?>#i", "<$1pre>", $data);
$data = preg_replace("#<p>|<p(?!re)[^>]*?".">|</p>#i", "",  preg_replace("#<\/p><p(?!re)[^>]*?".">#i", "\n", $data));
*/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.