OK, This is a request for comments on the following proposed new module:

CGI::FormBuilder::Template::HTML::LoopedVariables

=head2 _prepare_looped_variables This method exists to prepare fields which will ultimately be rendered + inside of loops by the template, to be prepared for inclusion. This + permits one to iterate over a database query and generate one or mor +e form fields for each record, which are rendered with HTML::Template +. This method is intended to add one new template construct: <tmpl-var field-looped-[field_name]> making possible the following code: my $form = CGI::FormBuilder->new( template => '/path/to/template/below.tmpl', header => $header, submit => [ 'Process Group Action' ] ); $form->field( name => 'group_action', label => 'Action', type => 'select', options => { 'add_to_group' => 'Add to Group', 'remove_from_group' => 'Remove from Group', 'edit_group' => 'Edit Group', 'delete_from_list' => 'Delete from List' } ); my @loop_data; while (my $phone = $sth->fetchrow_hashref()){ my %row_data; my $name = 'group_action_' . $phone->{'phone_number_id'}; $row_data{'CHECKBOX'} = \$form->field( name => $name, label => '', type => 'checkbox', options => [ 'perform_group_action' ], sticky => 0, value => 'perform_group_action', ); $row_data{'FNAME'} = $phone->{'fname'}; $row_data{'LNAME'} = $phone->{'lname'}; $row_data{'EMAIL'} = $phone->{'email'}; $row_data{'PHONE'} = $phone->{'phone'}; $row_data{'LINKS'} = $self->_get_links_for_phone_list($phone->{'ph +one_number_id'}); push (@loop_data, \%row_data); } $form->tmpl_param(PHONES => \@loop_data); my ($html); if ($form->submitted && $form->validate) { my $field = $self->{'q'}->Vars; if($form->submitted eq 'Process Group Action'){ if($field->{'group_action'} eq 'add_to_group'){ $self->_add_phone_numbers_to_group($field); $self->{'q'}->delete('_submitted_Group_Actions'); } elsif($field->{'group_action'} eq 'remove_from_group'){ $self->_remove_phone_numbers_from_group($field); $self->{'q'}->delete('_submitted_Group_Actions'); } elsif($field->{'group_action'} eq 'edit_group'){ $self->_edit_group($field); $self->{'q'}->delete('_submitted_Group_Actions'); } elsif($field->{'group_action'} eq 'delete_from_list'){ $self->_delete_phone_numbers_from_list($field); $self->{'q'}->delete('_submitted_Group_Actions'); } } $html = $form->render(); } else { $html = $form->render(); } Using a template like the one below: /path/to/template/below.tmpl <DIV align="right" id="GroupAction" class="GroupAction" title="Group_Action"> <h3>Group Actions:</h3> <table> <tmpl_var form-start> <tr><td colspan="2"></td><td colspan="2">Call Group: <tmpl_var field-group> Group Action: <tmpl_var field-group_action></td><td colspan="2"><tmpl_var form -submit></td></tr> <tr><th>Tag</th><th>First Name</th><th>Last Name</th><th>Email</th><th>Phone</th><th>Actions</th></tr> <tmpl_loop name="PHONES"> <tr><td> <tmpl-var field-looped-CHECKBOX> </td><td> <tmpl-var name=FNAME> </td><td> <tmpl-var name=LNAME> </td><td> <tmpl-var name=EMAIL> </td><td> <tmpl-var name=PHONE> </td><td> <tmpl-var name=LINKS> </td></tr> </tmpl_loop> <tmpl_var form-end> INSERT_NEW_RECORD_HERE </table> </DIV> =cut
This new module seems necessary to address the issues raised at: CGI::FormBuilder, HTML::Template and @loop_data question and CGI::FormBuilder, HTML::Template and \@loop_data question; trying again. Of course if anyone has any ideas for addressing this need more easily, I am all ears.

-- Hugh

if( $lal && $lol ) { $life++; }

In reply to 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.