CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
splitting ~~ CGI.pm

 



JFrost
Novice

Jul 9, 2001, 2:20 PM

Post #1 of 3 (1459 views)
splitting ~~ CGI.pm Can't Post

Here is my next problem.

I have been successful at setting up that when a user submits a field that has multiple values it will seperate each value with a ~~. Here is my next issue. I am using CGI.pm

print $q->checkbox_group('cuisine', \@cuisine, [$form_data{'cuisine'}], 'true');

The problem is, when I make modifications to the record, I don't have any checked checkboxes because it doesn't recognize the ~~, and therefore it doesn't find the values to be checked. So my question is, how do I split the field.


I hope you understand

Thanks



sleuth
Enthusiast

Jul 13, 2001, 11:36 AM

Post #2 of 3 (1443 views)
Re: splitting ~~ CGI.pm [In reply to] Can't Post

 
Well, you could do something like this, I'm not used to using CGI.pm unless I'm writting an upload script, but try this anyway.

Say you stored your checkboxes in $checkbox,

(@checks)=split(/~~/, $checkbox);

Then you could easily determine how many boxes were checked as well.

$count = @checks; # gives the number of boxes checked.

Also, if you needed to put the values into a hash, you could do this.

foreach $check (@checks){
$check{$check}=$check;
}

I use this method all the time and it's great for file manipulations.

This answer seems too simple for your question but maybe it'll help.

Tony



Jasmine
Administrator / Moderator

Jul 14, 2001, 3:09 PM

Post #3 of 3 (1432 views)
Re: splitting ~~ CGI.pm [In reply to] Can't Post


Code
# initiate instance 
my $in = CGI->new();


# create a sample delimited line
my $templine = '1~~3~~6~~9';

# simple array
my @fields = ( 1 .. 15 );

# create array of items split on ~~
my @checked = split( /~~/, $templine );


# let cgi.pm know the values that should already be checked.
$in->param( 'test' => @checked );

# output new checkbox group.
print $in->checkbox_group(
-name => 'test',
-values => \@fields,
-linebreak => 1
);


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives