Hello all:
Stumped again.
I am working to generate a form dynamically from database calls. Below hidden behind the readmore tags is a subroutine, a template and a bit of Data::Dumper output which I hope shows where I am at so far.
sub render_add_to_group_component2 {
my $self = shift;
my $list_id = shift;
my $header = $self->{'cfg'}->param("www.header");
my %args = (
name => 'Group_Actions',
method => 'post',
keepextras => 1,
sticky => 0,
template => $self->{'cfg'}->param("tmpl.tmpl_group_action_comp
+onent"),
stylesheet => $self->{'cfg'}->param("www.css"),
javascript => 0,
validate => {
group => 'WORD'
}
);
# print STDERR Dumper(\%args);
my $form = CGI::FormBuilder->new( \%args );
# print STDERR "The \$form object includes: \n" . Dumper($form);
my $groups = $self->_get_group_options();
unless(ref($groups) eq 'ARRAY'){ $groups = \(); }
# print STDERR Dumper($groups);
if(@{$groups}){
$form->field(
name => 'group',
label => 'Call Group: ',
type => 'select',
options => $groups,
);
}
$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 $insert_record = $self->render_insert_new_record_component($list_
+id);
my $sql = $self->{'cfg'}->param("sql.get_phones_for_list_id");
my $sth = $self->{'dbh_client_lists'}->prepare($sql);
$sth->execute($list_id);
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);
print STDERR "The loop_data incldes: \n" . Dumper(\@loop_data);
my ($html,$html_record);
if(defined($self->{'q'}->param("action")) && defined($self->{'q'}->p
+aram("record"))) {
if ($self->{'q'}->param("action") eq 'edit') {
$html_record = $self->_edit_phone_record($self->{'q'}->param("re
+cord"));
} elsif ($self->{'q'}->param("action") eq 'delete') {
$html_record = $self->_delete_phone_record($self->{'q'}->param("
+record"));
}
} else {
$html_record = "\n";
}
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( header => $header, submit => [ 'Process Gro
+up Action' ] );
$html =~ s/INSERT_NEW_RECORD_HERE/$html_record$insert_record/;
} else {
$html = $form->render( header => $header, submit => [ 'Process Gro
+up Action' ] );
$html =~ s/INSERT_NEW_RECORD_HERE/$html_record$insert_record/;
}
# print STDERR Dumper($self->{'q'}->Vars);
foreach my $key (keys %{$self->{'q'}->Vars}){
# print STDERR "The \$key is: $key \n";
if($key =~ m/group_action_/){
print STDERR "Now deleting \$key: $key \n";
$self->{'q'}->delete($key);
}
}
return $html;
}
The template:
<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>
</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> \n"
</tmpl_loop>
<tmpl_var form-end>
INSERT_NEW_RECORD_HERE
</table>
</DIV>
Some of the Data::Dumper output of \@loop_data:
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] The loop_data
+ incldes: , referer: http://192.168.15.51/cgi-bin/dashboard.cgi
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] $VAR1 = [, re
+ferer: http://192.168.15.51/cgi-bin/dashboard.cgi
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] {,
+referer: http://192.168.15.51/cgi-bin/dashboard.cgi
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] '
+LINKS' => '<a href="http://192.168.15.51/cgi-bin/dashboard.cgi?action
+=edit&record=90&CGISESSID=450eeedf233ef3bd096113b62d1694f7">Edit</a>
+* <a href="http://192.168.15.51/cgi-bin/dashboard.cgi?action=delete&r
+ecord=90&CGISESSID=450eeedf233ef3bd096113b62d1694f7">Delete</a>',, re
+ferer: http://192.168.15.51/cgi-bin/dashboard.cgi
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] '
+FNAME' => 'Testy',, referer: http://192.168.15.51/cgi-bin/dashboard.c
+gi
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] '
+EMAIL' => 'tt@ttc.com',, referer: http://192.168.15.51/cgi-bin/dashbo
+ard.cgi
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] '
+CHECKBOX' => 'perform_group_action',, referer: http://192.168.15.51/c
+gi-bin/dashboard.cgi
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] '
+PHONE' => '123-234-3456',, referer: http://192.168.15.51/cgi-bin/dash
+board.cgi
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] '
+LNAME' => 'Tester', referer: http://192.168.15.51/cgi-bin/dashboard.c
+gi
[Mon May 11 10:28:36 2009] [error] [client 192.168.15.4] },,
+ referer: http://192.168.15.51/cgi-bin/dashboard.cgi
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
if( $lal && $lol ) { $life++; }