سؤال

I am a newbie in Perl CGI . My code is shown below .

#!c:/xampp/perl/bin/perl.exe
use warnings;
use CGI;
my $q = CGI->new; 
print $q->header;
print "<html><head><title>Test</title></head>\n";
print '<body>';
@server = $q->param('sel');
if (!@server) 
{
    print '<p> please select a checkbox</p>';
    exit;
}
else
{
    print '<form action="next.pl" method="POST" id="sel" >';
    foreach my $i (@server) {
        print '<input type="checkbox" name="DEL"   value="';
        print $i;
        print ' checked ">';
        print $i;
        print '<br />';
    }
    print '<input type="submit" value="Kill">';      
    print '<form>';
    print '</body></html>';
} 

In the first part of the code i am getting the list of checkboxes ticked from the previous program using the checkbox name "sel" and storing it in an array server. I am using the same array in foreach loop and making it a checkbox with a name.

Now in my above code I don't want the checkboxes to be displayed . I want only submit button to be displayed. When i click the submit button i want my checked checkboxes in the form to go to next page.

How can i achive this . Please help .

هل كانت مفيدة؟

المحلول

One way to hide the checkboxes is to use a <span> tag:

use strict;
use warnings;
use CGI;
my $q = CGI->new; 
print $q->header;
print $q->start_html(-title => 'Test');
my @server = $q->param('sel');
if (!@server) {
    print $q->p('please select a checkbox');
    print $q->end_html();
    exit;
} else {
    print $q->start_form(-method => "POST", 
                         -action => "next.pl",
                         -id => "sel");
    print $q->span({hidden=>1},
          $q->checkbox_group(-name => "DEL",
                             -values => \@server,
                             -default => \@server,
                             ));
    print $q->submit(-name => "submit",
                     -value => "Kill");      
    print $q->end_form();
    print $q->end_html();
} 

I do prefer using the HTML building methods that CGI.pm provides. Helps to keep HTML out of the Perl.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top