You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Scott Chapman <sc...@mischko.com> on 2002/02/23 03:37:33 UTC

[OT] How to preserve carriage returns in text area inputs?

I'm finding that my form data is not preserving carriage returns.  When a user 
has a text area to fill in that is multiple lines, carriage returns are not staying 
in the $fdat{fieldname}.

If I take the data that is input on the form and on the next page output it 
again, it shows up as spaces where I pressed Enter.

Why is this and can I make it keep these carriage returns?

TIA!
Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: [OT] How to preserve carriage returns in text area inputs?

Posted by Angus Lees <gu...@switchonline.com.au>.
On Sat, Feb 23, 2002 at 04:42:16PM +0100, Gerald Richter wrote:
> >
> > If I take the data that is input on the form and on the next page output
> it
> > again, it shows up as spaces where I pressed Enter.
> >
> 
> The cr's are preseverd, but if you output a newline in html text, nothing
> happens...
> 
> So what you really want is to subsitute newlines with <BR> before outputing.

alternatively, just do: <pre>[+ $text +]</pre>

or even (if your browser is new enough):
 <div style="white-space:pre">[+ $text +]</div>

-- 
 - Gus

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: [OT] How to preserve carriage returns in text area inputs?

Posted by Gerald Richter <ri...@ecos.de>.
>
> If I take the data that is input on the form and on the next page output
it
> again, it shows up as spaces where I pressed Enter.
>

The cr's are preseverd, but if you output a newline in html text, nothing
happens...

So what you really want is to subsitute newlines with <BR> before outputing.
To get a 100% correct escaping of the rest of text, do something like (if
you simply subsitute \n with <br> you have to set $escmode to zero before
outputing, in which case the rest of the text is not correctly escaped)

[- @lines = split /\n/, $fdat{text} -]
[$foreach $l (@lines)$]
[+ $l +]<br>
[$endforeach$]

Gerald



-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: [OT] How to preserve carriage returns in text area inputs?

Posted by Andrew O'Brien <an...@switchonline.com.au>.
On Sat, Feb 23, 2002 at 03:07:15PM +1100, Andrew O'Brien wrote:
> On Fri, Feb 22, 2002 at 06:37:33PM -0800, Scott Chapman wrote:
> > I'm finding that my form data is not preserving carriage returns.  When a user 
> > has a text area to fill in that is multiple lines, carriage returns are not staying 
> > in the $fdat{fieldname}.
> > 
> > If I take the data that is input on the form and on the next page output it 
> > again, it shows up as spaces where I pressed Enter.
> > 
> > Why is this and can I make it keep these carriage returns?
> 
> The "wrap" attribute of the textarea tag is the one you want.
> 
> set it to "hard" to wrap at the display boundaries and at user entered
> return characters.
> 
> set it to "soft" to wrap only at user entered return characters
> (the display will still wrap but the lines will be sent as long
> strings)
> 
> The default is off. I usually set it to "hard" because I'm usually
> saving the output somewhere and so having a maximum column width is
> useful.

Whoops. Forgot to mention that
http://www.home.zonnet.nl/robschluter/htmltaglist/index_old.html
gives a comprehensive listing of all tags and attributes.

-- 
 Andrew O'Brien                                                               
 Senior Engineer                         email: andrewo@switchonline.com.au.
 Switch Online Group Pty Limited         phone: +61 2 9299 1133             
 ABN 89 092 286 327                      fax:   +61 2 9299 1134             

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: [OT] How to preserve carriage returns in text area inputs?

Posted by Andrew O'Brien <an...@switchonline.com.au>.
On Fri, Feb 22, 2002 at 06:37:33PM -0800, Scott Chapman wrote:
> I'm finding that my form data is not preserving carriage returns.  When a user 
> has a text area to fill in that is multiple lines, carriage returns are not staying 
> in the $fdat{fieldname}.
> 
> If I take the data that is input on the form and on the next page output it 
> again, it shows up as spaces where I pressed Enter.
> 
> Why is this and can I make it keep these carriage returns?

The "wrap" attribute of the textarea tag is the one you want.

set it to "hard" to wrap at the display boundaries and at user entered
return characters.

set it to "soft" to wrap only at user entered return characters
(the display will still wrap but the lines will be sent as long
strings)

The default is off. I usually set it to "hard" because I'm usually
saving the output somewhere and so having a maximum column width is
useful.

-- 
 Andrew O'Brien                                                               
 Senior Engineer                         email: andrewo@switchonline.com.au.
 Switch Online Group Pty Limited         phone: +61 2 9299 1133             
 ABN 89 092 286 327                      fax:   +61 2 9299 1134             

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org