Well, I dunno about it's kludge-worthiness, but for checkboxes, radio buttons, and selects for a quick form I had to do recently I went with extra template tags in the respective tags then in my script I set the appropriate values to 'selected' or 'checked' so my template looks like:

<p>[% error.message %]</p> <input type="checkbox" name="field1" value="1"[% checked.field1 %]> <select name="field2"> <option value="val1"[% selected.val1 %]>Value 1</option> <option value="val2"[% selected.val2 %]>Value 2</option> </select> <input type="radio" name="field3" value="a"[% checked.field3_a %]> <input type="radio" name="field3" value="b"[% checked.field3_b %]> <input type="radio" name="field4" value="a"[% checked.field4_a %]> <input type="radio" name="field4" value="b"[% checked.field4_b %]>

And after processing:

<p>Please select a value for Field 4</p> <input type="checkbox" name="field1" value="1" checked> <select name="field2"> <option value="val1">Value 1</option> <option value="val2" selected>Value 2</option> </select> <input type="radio" name="field3" value="a" checked> <input type="radio" name="field3" value="b"> <input type="radio" name="field4" value="a"> <input type="radio" name="field4" value="b">

Of course you're still going to have to process the input and set the appropriate values, but for that I created a config type hash containing the names of the different inputs grouped by type. For each I also specified a human readable label. Then I created a 'required' hash of input fields.

The script then checks that any fields in the 'required' hash have been specified and if not, uses their labels to create the error message.

Then we go through the field hashes to set appropriate values for 'selected' and 'checked'.

cheers,

J


In reply to Re: Re: Re: CGI.pm Disillusionment by edoc
in thread CGI.pm Disillusionment by Cody Pendant

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.