CGI::FormBuilder::Template::HTML::LoopedVariables
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.=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
-- Hugh
In reply to RFC: CGI::FormBuilder::Template::HTML::LoopedVariables by hesco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |