Forums

This topic is locked

forms and messages

Posted 24 Jul 2001 15:26:00
1
has voted
24 Jul 2001 15:26:00 Aaron Jay posted:
If I have a form that inserts information (text and alot of it) into a database, and I want it to come out all formatted by paragraphs, as someone would have entered it, what do i need to do? All of the stuff coming out of the database that was entered comes out as one solid body of text, as opposed to showing ti like page breaks. Any ideas?

Replies

Replied 24 Jul 2001 15:51:48
24 Jul 2001 15:51:48 Joel Martinez replied:
Here's a FAQ <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
www.udzone.com/showDetail.asp?TypeId=7&NewsId=1247

Joel Martinez

----------
Is this thing on?....
Replied 24 Jul 2001 19:02:13
24 Jul 2001 19:02:13 Bruno Mairlot replied:
This is a very common problem.

The problem is that when people enter text in a textarea and when they type Enter, the character \n is inserted.

This character is correctly stored in your database, but your problem is that when you output it, the \n is also outputed. And this character doesn't mean NOTHING in html.

You must replace all \n by a &lt;br&gt; code.

In PHP you have the function nl2br($string) that do it for you.


<i>Note that you can do it too with replacing \n by &lt;p&gt;, but it gives bigger space.</i>

Replied 24 Jul 2001 20:04:01
24 Jul 2001 20:04:01 Aaron Jay replied:
Ok so how would I do this in ASP using SQL 7.0 server? Would I use this string to interpret the information as it is entered, in the table, or as it is output to a page?


Replied 24 Jul 2001 20:27:14
24 Jul 2001 20:27:14 Bruno Mairlot replied:
Well,

what I usually does is to leave the text entered unmodified.

I just replace the \n when I print the text in an HTML structure.

I looked at the FAQ joelmartinez pointed, and it should be allright for you.

Replied 24 Jul 2001 20:34:49
24 Jul 2001 20:34:49 Joel Martinez replied:
straight from the FAQ you inspired.
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote> &lt;%= rs.fields("msgBody".value %&gt;

Change that, to this, and you're set...

&lt;%= replace(rs.fields("msgBody".value, VbCrLf, "&lt;br&gt;" %&gt;<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
I would do it as you output, because then you can put the value back into a textarea for editing, and you wont have the "&lt;br&gt;"'s in the textarea to mess with things...

Joel Martinez

----------
Is this thing on?....

Reply to this topic