Re: <textarea> input help



On 20 Nov, 15:06, "Jukka K. Korpela" <jkorp...@xxxxxxxxx> wrote:
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/

Ok thanks. Maybe i didn't explain myself properly.

before I out the string to the page before hand I take the POST data
and put it in a variable. then i use the PHP function str_split() to
put it into an array and I don't see any html codes in the array
entries where a carriage return should be.

for example in textarea
"hello

world"

gives $comment = [ 0 => h 1=> e 2=> l 3=> l 4=> o 5=> 6=> w 7=> o
8=> r 9=> l 10=> d ]

where at index 6 i should expect to see {cr}{lf} no? or will they just
not display in a browser, but I can be assured they are there.

when I say HTMLify, i mean turn string feed from input into standards
compliant HTML. that is, turn user entered comments into something i
can then display in the browser.

AND I also understand I will need to do this myself. but if I can't
see the format codes, i.e carriage returns or line breaks in what gets
sent to the server, then i can't process them and turn it into html.

AND i fully understand how html behaves, i.e. ignores all but one
whitespace etc etc.

any ideas?
.



Relevant Pages