textarea problem

C

cooldaddy

I've got a problem with a form's textarea. My script reads out the form
paramaters, and stores the content of the textarea into a string named
$line; To make sure all \n's in the string are replaced by <br> I use:
$line =~ s/\n/<br>/gs; Then I store this into a database.

In an other script I retreive these values and print them out.
It prints ok, however.. if the text in the textarea is wrapped (if the
user types all the way to the end of the textarea, and it continues
automaticly at the next line), the output to the screen is a lot
different then what was put in. How can I make it so that the output
looks the same way as the input ?
 
I

it_says_BALLS_on_your forehead

cooldaddy said:
I've got a problem with a form's textarea. My script reads out the form
paramaters, and stores the content of the textarea into a string named
$line; To make sure all \n's in the string are replaced by <br> I use:
$line =~ s/\n/<br>/gs; Then I store this into a database.

In an other script I retreive these values and print them out.
It prints ok, however.. if the text in the textarea is wrapped (if the
user types all the way to the end of the textarea, and it continues
automaticly at the next line), the output to the screen is a lot
different then what was put in. How can I make it so that the output
looks the same way as the input ?

i don't know if there exists some text-wrapping module, but if not,
then you could capture the width of the text area, and use a
combination of regexes (word boundaries) and substrings to simulate the
text-wrapping. is that what you mean by making the "output" look the
same as the "input"?
 
P

Paul Lalli

cooldaddy said:
I've got a problem with a form's textarea. My script reads out the form
paramaters, and stores the content of the textarea into a string named
$line; To make sure all \n's in the string are replaced by <br> I use:
$line =~ s/\n/<br>/gs; Then I store this into a database.

In an other script I retreive these values and print them out.
It prints ok, however.. if the text in the textarea is wrapped (if the
user types all the way to the end of the textarea, and it continues
automaticly at the next line), the output to the screen is a lot
different then what was put in. How can I make it so that the output
looks the same way as the input ?

You have two separate issues. One is that physical newlines typed by
the user should be replaced with <br> tags, as you did. The other is
that you seem to want implicit newlines also replaced. There are no
such newlines, however. How the text was displayed in the textarea was
at the mercy of the size of the text area box and the whimsy of the web
browser author.

Perhaps you simply want to wrap the text after a certain number of
chacters? I would look into: Text::Wrap

Paul Lalli
 
C

cooldaddy

Yes, i''ve looked at text::wrap before... but if I try the script
below... it prints out the 1-characters, but for some reason it
automaticly inserts spaces.

#!/usr/bin/perl -w
use CGI;
use Text::Wrap;
print "Content-type: text/html\n\n";

@text="11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
$Text::Wrap::columns = 60;
#print wrap('', '', @text);


print wrap("\t","",@text);
 
X

xhoster

cooldaddy said:
I've got a problem with a form's textarea. My script reads out the form
paramaters, and stores the content of the textarea into a string named
$line; To make sure all \n's in the string are replaced by <br> I use:
$line =~ s/\n/<br>/gs; Then I store this into a database.

In an other script I retreive these values and print them out.
It prints ok, however.. if the text in the textarea is wrapped (if the
user types all the way to the end of the textarea, and it continues
automaticly at the next line), the output to the screen is a lot
different then what was put in. How can I make it so that the output
looks the same way as the input ?

If you don't monkey with the "\n"s and you display the data in a textarea
control of the same dimensions as the one used in the input, then it will
look like the input did. If you display the output as plain html not in a
form element, then you can't generally make it look like the input did,
because the input was in a textarea and output will not be.

If you want to word-wrap the output to a certain line length, then word
wrap it. That has nothing to do with text areas or forms and little to do
with html. Maybe Text::Wrap would do.


Xho
 
P

Paul Lalli

Please quote an appropriate amount of context when replying to a post.
This would probably also be a good time for you to read the Posting
Guidelines for this group.


cooldaddy wrote, without quoting any context:
Yes, i''ve looked at text::wrap before... but if I try the script
below... it prints out the 1-characters, but for some reason it
automaticly inserts spaces.

#!/usr/bin/perl -w
use CGI;
use Text::Wrap;
print "Content-type: text/html\n\n";

@text="11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
$Text::Wrap::columns = 60;
#print wrap('', '', @text);


print wrap("\t","",@text);

I have no idea what you mean by that. The only "spaces" that were
automatically inserted were the tab on the first line (which you
explicitly requested in your non-commented call to wrap()), and the
newlines every 60 columns.

Can you provide sample output which does not match your expectations?

Paul Lalli
 
C

cooldaddy

Yeah i mean those automatically inserted tabs...how do i remove those ?

That cpan website doesnt help me a lot
 
A

A. Sinan Unur

I've got a problem with a form's textarea. My script reads out the
form paramaters, and stores the content of the textarea into a string
named $line; To make sure all \n's in the string are replaced by <br>
I use: $line =~ s/\n/<br>/gs; Then I store this into a database.

In an other script I retreive these values and print them out.
It prints ok, however.. if the text in the textarea is wrapped (if the
user types all the way to the end of the textarea, and it continues
automaticly at the next line), the output to the screen is a lot
different then what was put in. How can I make it so that the output
looks the same way as the input ?

How do you know what the input looked like?

This issue, which really has nothing to do with Perl, has been discussed
here before.

<URL:http://tinyurl.com/duoah>

By the way, you have been ask to quote properly before, and you seem to
simply refuse to follow advice. I won't be seeing you again.

Sinan
 
A

axel

Purl Gurl said:
Gunnar Hjalmarsson wrote:
Both Netscape and MSIE employ wraps: soft, hard and none. Those functions
are not specific to Netscape. Virtual wrap and Physical wrap are specific
to Netscape, years back, and are no longer suggested for use.
Soft, Hard and None work just fine and will continue to work just fine. Those
are core features in Netscape and MSIE browsers. Highly unlikely those features
will ever be removed.

Huh. I have never heard of any of those 'features'. Mainly because they do not
exist.

Axel
 
G

Gunnar Hjalmarsson

Purl said:
Both Netscape and MSIE employ wraps: soft, hard and none.

Have you tried wrap="hard" in Opera, one of the most standards compliant
browsers out there?
Soft, Hard and None work just fine

Only sometimes.
and will continue to work just fine.

And your source of info is...?

I do use "wrap" in a couple of old apps, but I'd not use it today. Since
it only works sometimes, since I prefer standards compliant HTML, and
since it's a yesterday's solution.
Use of hard wrap shifts processing to the client.

Use of Text Wrap shifts processing to the server.

It is a good habit to shift as much processing as possible
to the client,

In that case, I'm deliberately and systematically maintaining a bad
habit. ;-)
 
G

Gunnar Hjalmarsson

Purl said:
Is there a reason you are not providing information about Opera to
readers?

Opera users should go to the Opera user manual if they want to know how
it works.

In this case it works fine; the developers try to comply with the
current specifications, and in those the "wrap" attribute does not exist.

I wouldn't think of using "wrap" for something important; in the old
apps I mentioned it's just an extra benefit for those whose browsers do
not (yet) ignore "wrap".
 
S

Sherm Pendley

Purl Gurl said:
Another claims wrap attributes do not exist

A simple check at http://w3c.org will verify that no, wrap attributes are in
fact not part of standard HTML.

Sorry to interrupt the conversation with boring facts. You have my permission
to throw your usual "the evil Perl cabal is out to get me" tantrum now, if
you'd like.

sherm--
 
M

Matt Garrish

Gunnar Hjalmarsson said:
Have you tried wrap="hard" in Opera, one of the most standards compliant
browsers out there?


Only sometimes.


And your source of info is...?

Come on, you know better than to ask that!

In the year 2020 when css3 finally becomes a standard and is fully
implemented there will be text-wrap style, but she's not informed enough to
know about such things as cascading styles. I gather this attribute was one
of the failed experiments of the 4.x series of browsers that all but did
Netscape in (and many web developers!).

Matt
 
D

Dave Weaver

Yes, i''ve looked at text::wrap before...

Please quote some context in your messages; i.e. include a suitable
snippet of the message to which you're replying so that people who
can't see the whole thread know what on earth you're talking about.
but if I try the script
below... it prints out the 1-characters, but for some reason it
automaticly inserts spaces.

Only because you asked it to:
#!/usr/bin/perl -w
use CGI;
use Text::Wrap;

use strict;
use warnings;

Take all the help perl can give!
print "Content-type: text/html\n\n";

You're telling the web server that you're sending it HTML, and
yet you go on to just send plain text ...
Also, CGI.pm has a method for outputting the CGI headers;

print header( -type => 'text/plain' );
@text="11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
$Text::Wrap::columns = 60;
#print wrap('', '', @text);


print wrap("\t","",@text);
-----------------------^^
This asks for a tab to be used at the start of the first line. If you
don't want it, don't ask for it;

#!/usr/bin/perl
use strict;
use warnings;
use Text::Wrap;

my @text = "1" x 200;
$Text::Wrap::columns = 30;
print wrap('', '', @text);


outputs:
11111111111111111111111111111
11111111111111111111111111111
11111111111111111111111111111
11111111111111111111111111111
11111111111111111111111111111
11111111111111111111111111111
11111111111111111111111111

No tabs or spaces inserted there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top