I am working to generate a form dynamically from database calls.
I need to generate a form checkbox for each phone record pulled from my query. I would have thought that setting my %row_data{'CHECKBOX'} to a $form->field() object would have done the trick, but apparently not. Data::Dumper says it is: "'CHECKBOX' => 'perform_group_action'", instead of an entire form element. Commenting out the 'value' key leaves CHECKBOX undefined, commenting out the 'options' key throws errors reading: "No options specified for 'checkbox' field".
The name of the checkbox field changes on each iteration through the list. How do I invoke a "<tmpl-var field-checkbox>" with a changing fieldname and embedded in rows of my template?
I'm looking for a clue here. Anybody have one to spare?
-- Hugh
My template reads:
------------------------------------<DIV align="right" id="GroupAction" class="GroupAction" title="Group_A +ction"> <h3>Group Actions:</h3> <table> <tmpl_var form-start> <tr><td colspan="2"></td><td colspan="2">Call Group: <tmpl_var field-g +roup> 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-checkbox> </td><td> <tmpl-var name=FNAME> </t +d><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>
And the problematic portion of my code reads:
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->{'p +hone_number_id'} ); push (@loop_data, \%row_data); } $form->tmpl_param(PHONES => \@loop_data); print STDERR "The loop_data incldes: \n" . Dumper(\@loop_data);
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |