Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving and loading checkbox_group values 1

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
0
0
GB
I am quite familiar with Perl generated checkboxes but I have an app which has quite a number of extras and I would rather not create a separate field in my table for each one.
I turned to checkbox-group and I have hit a snag.
Create the control and populate it from an array.
Code:
$EXTRUS= $query->checkbox_group(
-name=>'EXTRAS',
-values=> \@Extras,
-linebreak=>'true',
-default=>'');

Submitting the form containing the control, sends multiple values for selected items, in the form of an array.

Code:
my @boxes=$query->param('EXTRAS');
my $bitz;
foreach $bitz (@boxes){
print "*$bitz*";
}
So far so good but by default, only the first item is stored in my table.
I can iterate through the array, and store all the values as a string containing separators but how do I repopulate the correct checkboxes when I reload the form from my table?
I am sure I could work it out with code but operations of the CGI module are usually a lot simpler than that.



Keith
 
Rather than leave one of those annoying unanswered threads.

The documentation for this is very poor and several websites even state it cannot be done.

$FieldValue is loaded from the table and split into @SelectedExtras.
Assign the query param the whole array.


Code:
$FieldValue="LEMONxaxLIMExaxORANGExax";

@SelectedExtras= split(/xax/,$FieldValue);
foreach $bitz (@SelectedExtras){
	push(@CheckedExtras, $bitz);
}
$query->param("EXTRAS", @CheckedExtras);

my $EXTRUS= $query->checkbox_group(-name=>'EXTRAS',
	-values=> \@Extras,
	-linebreak=>'true',
	-default=>'');

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top