in reply to Re: Re: CGI.pm Disillusionment
in thread CGI.pm Disillusionment

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