confusion with formatting textarea content with SMF/PHP and MySql

Started by mano82, July 25, 2015, 04:29:46 AM

Previous topic - Next topic

mano82

I was able to make a functioning mod myself that adds a section to the portal with user content.
This mod grants the user to add content to the site through a form containing textareas. This content is recored to the database and then it can be viewed or edited. In the meantime when the user submit the content, a forum post is created reporting the same content.

This all works fine however there is a stylish issue that I'm not able to solve.

In the Insert Form I have 3 textareas that may contain formatted text (i.e. new lines break, bold, italic), that I would like to format in BBC code. Actually I don't know how to do that...

When I write the textarea content the newlines are correctly copied to the database and represented in the EDIT mode of the form, but in the VIEW mode of the form they are not, and all the content is shown in a single line. (note: the forum post shows them correctly).

Example.

this is the content of my textarea in INSERT FORM:
First Line
Second Line

Third line (empty line above)


Database, EDIT Form (in a textarea) and forum post show the same formatting.

the VIEW mode of the mod show the following:
First Line Second Line Third line (empty line above)

Note that the INSERT and EDIT form contain the text into a textarea, while the VIEW shows the text into a <p>aragraph.

Now, I've found the way to correctly show the content in the VIEW area that is by preformatting the form entry while saving to the database, i.e.:
$myform['content'] = $smcFunc['htmlspecialchars']($myform['content'], ENT_QUOTES);
preparsecode($myform['content']);


This makes my VIEW area show my content like it was inserted:
First Line
Second Line

Third line (empty line above)


However when I go into EDIT mode, the content of my textarea shows html tags like this:
First Line<br />Second Line<br /><br />Third line (empty line above)

and if I save the content then the HTML tags are not parsed again and show into the VIEW <p>...

I understand there is something to do when I save to database or when I get from database and put into the EDIT Form, but I don't understand which function to use.

I've tried to use un_preparsecode, and the following on the content to be put into the editing textarea:
$context['content'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), un_preparsecode($context['content']));

but with no success...

and the BBC code is not shown in the VIEW <p>aragraph....

any help?
thanks in advance

mano82

Ehm SORRY... I solved it...It actually works, but I did some mistakes in other parts of the code!!!!   ::) ::)

However, I would like to ask help for the bbc formatting part...that still is not working...

many thanks!

Advertisement: