Wow. I am baffled by how many of the above examples actually embed the html in the CGI and try and interpolate the values directly into the html. This is only marginally less offensive as interpolating variables into SQL (not using placeholders).

Use either CGI::Ex::Fill or HTML::FillInForm to get your values into the form.

I'll leave it to you whether you generate your form dynamically, or if you use a static generated form, or a hybrid dynamic/static form created using a template system (you are using a templating system right?). The fill methods allow for generating the form however and then getting the values into the right places.

use CGI; use CGI::Ex::Fill qw(fill); my $q = CGI->new; my %default = ( foo => 'FooFoo', bar => 'BarBar', baz => 'BazBaz', ); foreach my $k (keys %default) { $q->param($k, $default{$k}) if ! defined $q->param($k); } my $html = ' <form> <input type="text" name="foo"> <textarea name="bar"></textarea> <select name="baz"> <option>Bing</option> <option>BazBaz</option> <option>Bang</option> </form> '; fill({text => \$html, form => $q}); print $html;
Which would print the following:
<form> <input type="text" name="foo" value="FooFoo"> <textarea name="bar">BarBar</textarea> <select name="baz"> <option>Bing</option> <option selected="selected">BazBaz</option> <option>Bang</option> </form>


my @a=qw(random brilliant braindead); print $a[rand(@a)];

In reply to Re: Sticky Forms by Rhandom
in thread Sticky Forms by JsnHendry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.