Until recently I have used the strategy that you have shown above. I would now suggest using Data::URIEncode.

You would begin by using a form that looks similar to the following:

<form ...> <table> <tr> <td><b>Username 1</b></td> <td><input type=text name="users:0.username"></td> </tr> <tr> <td><b>Email</b></td> <td><input type=text name="users:0.email"></td> </tr> <tr> <td><b>Name</b></td> <td><input type=text name="users:0.name"></td> </tr> </table> <table> <tr> <td><b>Username 1</b></td> <td><input type=text name="users:1.username"></td> </tr> <tr> <td><b>Email</b></td> <td><input type=text name="users:1.email"></td> </tr> <tr> <td><b>Name</b></td> <td><input type=text name="users:1.name"></td> </tr> </table> </form>


So far so easy. You can use pretty much whatever templating tools you want for generating the html - clear from hard coded html (don't do that), to CGI html methods, to Template::Toolkit (I'd suggest doing that).

When the form is posted to cgi script, just pass the CGI query through Data::URIEncode.

use CGI; use Data::URIEncode qw(query_to_complex); use Data::Dumper qw(Dumper); my $q = CGI->new; my $data = query_to_complex($q); print "Content-type: text/plain\n\n"; print Dumper $data; __END__ Will have printed something similar to: $VAR1 = { users => [{ username => "...", email => "...", name => "...", },{ username => "...", email => "...", name => "...", }], };


You'll still need to do all of the validation, but getting the records into the right structure is already done.

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

In reply to Re: Strategy to name/process many similar form fields with cgi.pm? by Rhandom
in thread Strategy to name/process many similar form fields with cgi.pm? by punch_card_don

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.