If I understood your original question correctly (and I am not sure I did), you would like to generate an HTML table where each row contains some contact information and a checkbox. At the top of the form is a set of group actions. When the form is processed you want to apply the group actions to each table row where the checkbox is checked.

I'm not terribly familiar with the modules central to this issue, but since you seem to have gone quite a while without a solution, I'm going to give it a shot based on reading the module documentation.

As near as I can tell from the documentation, CGI::FormBuilder only knows how to build one form in a template, not an array of forms. It seems that your first way of working around this was to treat all of the table rows as one big form and use <tmpl_loop> to generate each row. But this created another problem: how do you tell one row from another? CGI::FormBuilder only returns a hash keyed by field name. If all rows in the table have the same field names, how do you know which row is assigning the value to the field?

In your various posts you've tried at least two solutions:

I don't think either will work because the core problem isn't in CGI::FormBuilder nor in HTML::Template, but rather in how the two work together. CGI::FormBuilder is expecting you to generate a single form, not an array of forms. It appears to be matching the name of the field definition in your field array with the name of the field in the template definition. If your field array contains definitions for fields "checkbox_1" and "checkbox_2", but your template only contains a field "checkbox", CGI::FormBuilder doesn't know how to connect the field definitions to the template definition.

If you look at all of the examples for CGI::FormBuilder they all involve non-repeating forms. If you really want to use CGI::FormBuilder and HTML::Template together to build a table, I suspect that you will need to manually generate a template where each table row contains a different set of form fields, doing something like this (pseudo code):

#start table template my $sTemplate='<table><tmpl_var form-start>...<tr>...</tr>'; #generate table rows foreach my $iRow (0... $#loopData) { #generate field definitions qualified by row id # e.g. FNAME_$iRow # LNAME $iRow # CHECKBOX $iRow # append field definitions to row fields push @aFields, @aRowFields; # generate a template string using the above fieldnames $sTemplate .= "<tr>...<tmpl-var field-checkbox_$iRowId>...</tr>"; } #finish table $sTemplate='<tmpl_var form-end>INSERT_NEW_RECORD_HERE</table>'; #write template string out to a temp file #generate form using the temp file my $oForm = CGI::FormBuilder->new( fields => \@aFields, ... template => 'tmpForm.tmpl' ); $oForm->render();

Best, beth


In reply to Re: RFC: CGI::FormBuilder::Template::HTML::LoopedVariables by ELISHEVA
in thread RFC: CGI::FormBuilder::Template::HTML::LoopedVariables by hesco

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.