textarea problem

Discussion in 'Perl Misc' started by cooldaddy, Oct 11, 2005.

  1. cooldaddy

    cooldaddy Guest

    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 ?
     
    cooldaddy, Oct 11, 2005
    #1
    1. Advertising

  2. 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"?
     
    it_says_BALLS_on_your forehead, Oct 11, 2005
    #2
    1. Advertising

  3. cooldaddy

    Paul Lalli Guest

    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
     
    Paul Lalli, Oct 11, 2005
    #3
  4. cooldaddy

    cooldaddy Guest

    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);
     
    cooldaddy, Oct 11, 2005
    #4
  5. cooldaddy

    Guest

    "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
     
    , Oct 11, 2005
    #5
  6. cooldaddy

    cooldaddy Guest

    xho, please notice my earlier posting about text::wrap
     
    cooldaddy, Oct 11, 2005
    #6
  7. cooldaddy

    Paul Lalli Guest

    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
     
    Paul Lalli, Oct 11, 2005
    #7
  8. cooldaddy

    cooldaddy Guest

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

    That cpan website doesnt help me a lot
     
    cooldaddy, Oct 11, 2005
    #8
  9. 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/forms/_TEXTAREA_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
     
    Gunnar Hjalmarsson, Oct 11, 2005
    #9
  10. "cooldaddy" <> wrote in
    news::

    > 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/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Oct 11, 2005
    #10
  11. cooldaddy

    Guest

    Purl Gurl <> wrote:
    > Gunnar Hjalmarsson wrote:


    >> 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.


    > 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
     
    , Oct 11, 2005
    #11
  12. cooldaddy

    John Bokma Guest

    John Bokma, Oct 11, 2005
    #12
  13. Purl Gurl wrote:
    > Gunnar Hjalmarsson wrote:
    >> Purl Gurl wrote:
    >>> 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.

    >
    > 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. ;-)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 11, 2005
    #13
  14. Purl Gurl wrote:
    > 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".

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Oct 11, 2005
    #14
  15. Purl Gurl <> writes:

    > 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--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Oct 11, 2005
    #15
  16. cooldaddy

    Matt Garrish Guest

    "Gunnar Hjalmarsson" <> wrote in message
    news:...
    > Purl Gurl wrote:
    >> Gunnar Hjalmarsson wrote:
    >>> Purl Gurl wrote:
    >>>> 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.

    >>
    >> 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...?
    >


    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
     
    Matt Garrish, Oct 12, 2005
    #16
  17. cooldaddy

    Dave Weaver Guest

    On 11 Oct 2005 10:43:54 -0700, cooldaddy <> wrote:
    > 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.
     
    Dave Weaver, Oct 12, 2005
    #17
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. angus
    Replies:
    0
    Views:
    1,151
    angus
    May 20, 2004
  2. Param R.

    textarea problem

    Param R., Oct 28, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    340
    Param R.
    Oct 28, 2004
  3. Augustus
    Replies:
    1
    Views:
    361
    Ken Schaefer
    Sep 10, 2003
  4. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    336
    Anthony Jones
    Feb 5, 2006
  5. Replies:
    1
    Views:
    319
    Bart Van der Donck
    Jul 4, 2007
Loading...

Share This Page