Loading ...
Sorry, an error occurred while loading the content.

Problem with text box in an HTML form.

Expand Messages
  • Andy Schafer
    Hi, I know this isn t strictly a Perl problem but it is in a Perl script so I thought I would ask anyway. On my site I have a simple flat file database. Each
    Message 1 of 4 , Nov 23, 2007
    • 0 Attachment
      Hi,

      I know this isn't strictly a Perl problem but it is in a Perl script
      so I thought I would ask anyway.

      On my site I have a simple flat file database. Each entry is 10 lines.
      One line is the description of the item and contains some html tags to
      format the text when it is displayed on my site. There are also some
      that contain special characters such as " & $ ( ) etc.

      The problem I have is this. I have a Perl script that allows me to
      edit a database entry. It gives me a form with a text box for each of
      the 10 lines. The "value" parameter of each text box is set to
      whatever is currently shown in the database. The problem is that when
      the text box for the description line encounters an entry containing
      special characters or html tags it doesn't just show the entry "as-is"
      from the database. Instead the special characters screw it up. For
      instance entries containing a <br> tag jump outside the textbox with
      part of the information.

      So my question is this, is there a way to force the textbox to display
      the information exactly the way it is supposed to be, html tags and all?

      I have been hunting through my books and on the net but I don't even
      know what to look for. If anyone can help I'd appreciate it very much!

      Thanks in advance,
      Andy Schafer
    • merlyn@stonehenge.com
      ... Andy The problem I have is this. I have a Perl script that allows me to Andy edit a database entry. It gives me a form with a text box for each of Andy
      Message 2 of 4 , Nov 23, 2007
      • 0 Attachment
        >>>>> "Andy" == Andy Schafer <lostgameparts@...> writes:

        Andy> The problem I have is this. I have a Perl script that allows me to
        Andy> edit a database entry. It gives me a form with a text box for each of
        Andy> the 10 lines. The "value" parameter of each text box is set to
        Andy> whatever is currently shown in the database. The problem is that when
        Andy> the text box for the description line encounters an entry containing
        Andy> special characters or html tags it doesn't just show the entry "as-is"
        Andy> from the database. Instead the special characters screw it up. For
        Andy> instance entries containing a <br> tag jump outside the textbox with
        Andy> part of the information.

        How are you generating your html? If you're using CGI.pm, for example,
        you merely have to use:

        print textarea(-name => 'param_name', -default => $existing_value);

        and CGI.pm will do the right escaping. Other templating languages
        have similar features.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • Jenda Krynicky
        From: Andy Schafer ... Escape! use HTML::Entities; #... print qq{
        Message 3 of 4 , Nov 24, 2007
        • 0 Attachment
          From: "Andy Schafer" <lostgameparts@...>
          > On my site I have a simple flat file database. Each entry is 10 lines.
          > One line is the description of the item and contains some html tags to
          > format the text when it is displayed on my site. There are also some
          > that contain special characters such as " & $ ( ) etc.
          >
          > The problem I have is this. I have a Perl script that allows me to
          > edit a database entry. It gives me a form with a text box for each of
          > the 10 lines. The "value" parameter of each text box is set to
          > whatever is currently shown in the database. The problem is that when
          > the text box for the description line encounters an entry containing
          > special characters or html tags it doesn't just show the entry "as-is"
          > from the database. Instead the special characters screw it up. For
          > instance entries containing a <br> tag jump outside the textbox with
          > part of the information.
          >
          > So my question is this, is there a way to force the textbox to display
          > the information exactly the way it is supposed to be, html tags and all?

          Escape!

          use HTML::Entities;
          #...

          print qq{<intput type="text" name="whatever" value="} .
          encode_entities($whatever) . qq{" onChange="modifiedWhatever()">\n};


          Or, if you do not want to have to close the string, you can use
          Interpolation:


          use HTML::Entities;
          use Interpolation HTML => \&encode_entities;

          print qq{<intput type="text" name="whatever" value="$HTML{$whatever}"
          onChange="modifiedWhatever()">\n};


          HTH, Jenda
          ===== Jenda@... === http://Jenda.Krynicky.cz =====
          When it comes to wine, women and song, wizards are allowed
          to get drunk and croon as much as they like.
          -- Terry Pratchett in Sourcery
        • Andy Schafer
          Hey Jenda, Thank you so much for your input. I used the solution below that you gave and it works great!! I am very greatful! ... Thank you to all of you who
          Message 4 of 4 , Nov 25, 2007
          • 0 Attachment
            Hey Jenda,

            Thank you so much for your input. I used the solution below that you
            gave and it works great!! I am very greatful!

            Jenda Wrote:
            > use HTML::Entities;
            > #...
            >
            > print qq{<input type="text" name="whatever" value="} .
            > encode_entities($whatever) . qq{" onChange="modifiedWhatever()">\n};

            Thank you to all of you who took the time to read my question! This a
            really great group!

            Thank you
            Andy Schafer
          Your message has been successfully submitted and would be delivered to recipients shortly.