Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Storing text from a <form> without loosing linebreaks.

Posted on 1998-08-28
15
Medium Priority
?
159 Views
Last Modified: 2013-12-25
I need help. I need to be able to store the text from a "textarea" in a table and retrieve it again without loosing the linebreaks made when "return" is pressed during the typing in the field. I am using ASP.
0
Comment
Question by:aspdev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 4
  • +1
15 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 1854626
You could use the normal procedure, "returns" are saved into the database as well. The contents of a <TEXTAREA> should be stored into a memo-field (using Access), or a field of the type "text" (using MS SQL).

If you really want to be sure (and avoid trouble with quotes), you could URLEncode the text before storing it (Server.URLEncode) and decode it again before displaying.

0
 

Author Comment

by:aspdev
ID: 1854627
I store it in a MS SQL "text" field. I even URLEncode it, but the "returns" still ain't there... what is the problem? I add the data by calling it with Request.Form("Info")...
0
 
LVL 28

Expert Comment

by:sybe
ID: 1854628
The returns are converted to %something when the string is urlencoded, you have to decode it to get them back.
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
LVL 28

Expert Comment

by:sybe
ID: 1854629
Oh and by the way, a return in text, is not a return in HTML, if you want the returns to be converted to HTML, then use a replace function, which replaces the returns with "<p>" or "<br>".

REPLACE(YourString, CHR(10), "<p>")
will replace linefeed
CHR(13) is carriage return, you might want to use that maybe.

0
 
LVL 1

Expert Comment

by:Bluemoon
ID: 1854630
mayby you shoud place int in a textarea of 0x0 in the table
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1854631
Use the "wrap=virtual" flag:

<textarea wrap=virtual ...>

//madduck
0
 

Author Comment

by:aspdev
ID: 1854632
That didn't work. No diffrence at all.
I came up with the idea to URLEncode the the data and then replace all "%0D%0A" with "<br>" before I URLDecode it. The problem is that I lose all "spaces" since they are converted into a "+" sign and If I change that to spaces, then I'd lose the "real" +:es.
What I need to do is to (store) and later retrieve the whole text including "returns".
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1854633
Now I get it. A real + would be coded as %20, so you would first convert "+" to " " and then "%20" to "+".

How about using a CGI library? This will do it for you!
0
 

Author Comment

by:aspdev
ID: 1854634
I solved it on my own. I really aprreciate your help, especially sybe who, I could give some credit for the idea with CHR(13). Had to do some more things though... oh well... thank you all!
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1854635
sybe, then please answer this so that aspdev cxan award you.

later pals!
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1854636
oh yeah, and aspdev, please tell us quickly what you did so that this question is a useful PAQ!
0
 

Author Comment

by:aspdev
ID: 1854637
Sorry.
I HTMLEncoded it before I stored it in the database.
Then I retrived it and replaced all CHR(13) with "<br>". To enable a person to add more than one "space" in a row, I added that it also changed the " " to "&#160;".


0
 

Author Comment

by:aspdev
ID: 1854638
And one more thing, it is useful to relace only "  " (notice the TWO spaces) with " &#160;" since you otherwise will have onle long line with what for the browser looks like one word "and&3160;then&#160;I&#160;" ect. That will disable the wordwrapping. So only replace when it is more than one space and replace with one space and one &#160;
0
 
LVL 28

Accepted Solution

by:
sybe earned 40 total points
ID: 1854639
So I guess I can answer the question and collect the points.
Thanks

0
 

Author Comment

by:aspdev
ID: 1854640
I guess you could. Want to say thanx to madduck too but you are the one who gave me part of the idea to the solution. Thanx! here you are.
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question