in reply to Printing quotes out to an html form?

There are a few ways you can do this:
  1. Scrap your code and build it with CGI instead. Attribute arguments are already automatically quoted for you.
  2. Use your existing code in conjunction with the CGI module. At a minimum, you can use &CGI::escapeHTML, though I'm not sure that this is a function meant for public consumption.
  3. Just write some code to do your own escaping. s/"/\\"/g;

Replies are listed 'Best First'.
Re: Re: Printing quotes out to an html form?
by Anonymous Monk on Jan 02, 2001 at 20:31 UTC
    Im using CGI, but the string is taken from a text file and printing to a form, not the other way around.
      Well then, follow Fastolfe's second suggestion.
      use CGI; # you already have this line $q = new CGI; # and one like this to I suppose my $var = "some text from a file"; my $varesc = $q->escapeHTML($var);

      --
      $you = new YOU;
      honk() if $you->love(perl)

      well, if you are using CGI.pm then why not use the textfield method? it escapes html for you (it uses the escapeHTML() method internally):
      use CGI; my $q = new CGI; my $value = '<img src="/someimg.gif">'; print $q->start_html(), $q->start_form(), $q->textfield( -name=>'test', -value=>$value), $q->end_form, $q->end_html;
      it works great!