in reply to RFC: CGI::FormBuilder::Template::HTML::LoopedVariables

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