[sf-perl] Those darn check boxes ...

Thomas Brightbill thomas at brightbill.net
Thu Jun 5 17:57:41 PDT 2008


Ken,

Does the following example get you closer to where you're trying to go?

Thomas Brightbill
thomas at brightbill.net
http://www.brightbill.net


------------------------------------------------------------------------
#!/usr/bin/perl

use CGI;
use strict;

my $q = new CGI;
my $called_by   = $q->param('submit');
my $confirmed   = $q->param('confirmed');
my $script_name = "tagbucket_template";

my ($message,$formstuff);


# check how we were called

if ($called_by ne 'submit') {

  # this is the first time the form is displayed

  # get some names from a database

  # assume for now that the database returns an array
  # with something like the following

  my @results = ('red','orange','yellow','green','blue','indigo','violet');

  $formstuff = $q->checkbox_group(-name=>'tagbucket',
                                  -values=>\@results,
                                  -linebreak=>'true');

} else {

  if ($confirmed ne 'yes') {

    # this is the confirmation page

    my @stuff_to_delete = $q->param('tagbucket');

    $message  = $q->p("Are you sure you want to delete the following items?");
    $message .= $q->ul($q->li(\@stuff_to_delete));

    $formstuff  = $q->hidden(-name=>'tagbucket',\@stuff_to_delete);
    $formstuff .= $q->checkbox(-name=>'confirmed', -value=>'yes',
                               -label=>'Yes, I want to delete this stuff!');
    $formstuff .= $q->br();

  } else {

    # this is the actual deletion

    my @stuff_to_delete = $q->param('tagbucket');

    # delete stuff from database

    # create confirmation message

    $message  = $q->p("The following stuff has been deleted:");
    $message .= $q->ul($q->li(\@stuff_to_delete));

  }
}


# page output

print $q->header;
print $q->start_html('Tagbucket Template');

print $q->p($message);

print qq|<form action="$script_name" method="POST">\n|;
print $formstuff;
print $q->submit( -name => 'submit', -value => 'submit');
print $q->end_form;

print $q->end_html;


More information about the SanFrancisco-pm mailing list