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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|