Re: <textarea> input help
- From: "Jukka K. Korpela" <jkorpela@xxxxxxxxx>
- Date: Tue, 20 Nov 2007 17:06:03 +0200
Scripsit Icarus - iD_Ten_T helper:
I want to parse the text from a <textarea> form element but when I
pass this in a POST request to the server and then output it using
PHP, all formatting is gone.
If you take data from a textarea as sent by a browser and then paste this data as such into an HTML document, as content, then indeed the formatting of the text is gone. This applies to formatting like the use of newlines, tabs, and multiples spaces - they each turn into a single space. This however has nothing special to do with textarea. Rather, it's the way HTML "works" for text in general. If you look at the HTML source of the generated page, the formatting is there (unless your processing specifically changed it).
I was under the impresssion that the textbox would register any
carriage returns or line breaks and send them in the final text for
processing?
Only those entered by the user, not those generated by a browser when the text does not fit into the visible space reserved for the textarea.
Is there any way of forcing the textarea input to send formatting data
as well?
The formatting is sent, but when turned into HTML document content, it will be ignored by HTML rules.
Essentially the idea would be to turn a text box with this in:
"Hello <= carriage return
<= line break
World <= carriage return
<= line break
Foo <= carriage return
<= line break
Bar"
into
"<p>Hello</p>
<br />
<p>World</p>
<br />
<p>Foo</p>
<br />
<p>Bar</p>"
Well, maybe, maybe not. Can you break a nonexistent line? The use of <p>...</p> should be sufficent.
but i can't do this is the received string at the server is does not
contain any reference to those line breaks of carriage returns.
It contains a line break encoded as CR LF pair, by HTML specifications. How you process the data, recognizing such line breaks and replacing them by HTML markup, is external to HTML. It depends on the server-side technology.
I can't HTMLify it if you will.
Understand that statement I cannot. Anyway, I won't HTMLify it, but I told you the basic idea of doing it.
--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/
.
- Follow-Ups:
- Re: <textarea> input help
- From: Icarus - iD_Ten_T helper
- Re: <textarea> input help
- References:
- <textarea> input help
- From: Icarus - iD_Ten_T helper
- <textarea> input help
- Prev by Date: Re: firefox <fieldset> oddity?
- Next by Date: Re: <textarea> input help
- Previous by thread: <textarea> input help
- Next by thread: Re: <textarea> input help
- Index(es):
Relevant Pages
|