Gossamer Forum
Home : General : Perl Programming :

creating the Form using CGI.pm?

Quote Reply
creating the Form using CGI.pm?
I have made this script using CGI.pm for the first time in my life (otherwise I was using typical require cgi-lib.pl and typical parse_form subroutines)

One of the subroutine (ip_unban) belongs to another poster : Zeshan (thank you!) recently posted by him.

Since, this is my first script. I have understood how to make forms with CGI.pm, the problem I am facing is calling the variables in the subroutines. See the &make_form; subroutine below.

Thanks for any input.

Sara.

#!/usr/bin/perl

use strict;
use warnings;

use CGI::Carp 'fatalsToBrowser';

use CGI qw(:standard);

my $q = new CGI;

my $ipban = $q->param('ipban') || '96.23.823.23';

my $action = $q->param('action') || 'unban';

if ($action eq "ban") {
&ban_ip;
}
elsif ($action eq "unban") {
&unban_ip;
}
else {
&make_form;
}

sub ban_ip {
open (IP, ">>ipban.txt");
print IP "$ipban\n";
close (IP);
print header,
start_html('Success IP banned'),
h1('The IP has banned Successfully'),
($ipban),
end_html;
}

sub unban_ip {
my $infile;
my $outfile;
my $line;
$infile="ipban.txt";
$outfile="temp.txt";
open (IN, "$infile");
open (OUT, ">$outfile");
my @temp;
@temp=<IN>;
foreach $line (@temp) {
if($line !~ m/$ipban/i)
{
print OUT $line;
}
}
close (IN);
close (OUT);

unlink ($infile);

rename ($outfile, $infile);

print header,
start_html('Unban Success'),
h1('The IP was Unbanned successfully'),
$ipban,
end_html;

}

sub make_form {
print header,

HERE I AM AT A LOSS AS WHAT TO DO TO MAKE FORM WHICH WOULD
open Ipban.txt
list all the remaining IPs in the checkboxes, so that user can select one more
to delete and submit the form again.


end_html;

}

exit;

Last edited by:

Sara_Samsara: May 26, 2003, 4:53 PM
Subject Author Views Date
Thread creating the Form using CGI.pm? Sara_Samsara 2850 May 26, 2003, 4:50 PM
Post Re: [Sara_Samsara] creating the Form using CGI.pm?
Paul 2691 May 26, 2003, 4:55 PM