Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > textarea problem

Reply
Thread Tools

textarea problem

 
 
cooldaddy
Guest
Posts: n/a
 
      10-11-2005
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 ?

 
Reply With Quote
 
 
 
 
it_says_BALLS_on_your forehead
Guest
Posts: n/a
 
      10-11-2005

cooldaddy wrote:
> 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"?

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      10-11-2005
cooldaddy wrote:
> 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

 
Reply With Quote
 
cooldaddy
Guest
Posts: n/a
 
      10-11-2005
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="1111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 11111111111111111111111111111";
$Text::Wrap::columns = 60;
#print wrap('', '', @text);


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

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      10-11-2005
"cooldaddy" <> wrote:
> 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

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
cooldaddy
Guest
Posts: n/a
 
      10-11-2005
xho, please notice my earlier posting about text::wrap

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      10-11-2005
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="1111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 11111111111111111111111111111";
> $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

 
Reply With Quote
 
cooldaddy
Guest
Posts: n/a
 
      10-11-2005
Yeah i mean those automatically inserted tabs...how do i remove those ?

That cpan website doesnt help me a lot

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      10-11-2005
Purl Gurl wrote:
> cooldaddy wrote:
>> 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),

>
> http://www.htmlcodetutorial.com/form...AREA_WRAP.html
>
> Use hard wrap.


That Netscape attribute may still work in many browsers, but there is no
"wrap" attribute in any HTML specification, so it may stop working anytime.

I'd go for a text wrapping module, as others have suggested.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-11-2005
"cooldaddy" <> wrote in
news: oups.com:

> 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. Sinan Unur <>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add </textarea> within <textarea> tags? frank.moens@gmail.com Javascript 1 07-04-2007 04:00 PM
Textarea Inside of a textarea wperry1@gmail.com ASP General 6 02-05-2006 08:00 AM
textarea problem Param R. ASP .Net 0 10-28-2004 02:42 PM
problem of using multiline text box(textarea) in datagrid angus ASP .Net 0 05-20-2004 03:01 PM
Removing carriage returns from <textarea></textarea> input Augustus ASP General 1 09-10-2003 04:55 AM



Advertisments