On Saturday May 24 2003 6:49 am, Sara wrote:
> 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)
>
> 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;


if I understand you question correctly , you don't know how to use CGI.pm to 
create a form ?  There are several ways of approching  it , you can use the 
object orentated way using the "$q->" method calls , or you can  do it  by 
using the  "here doc" method  or  using the non OOP methods .  bets way to 
lear is to  look in the CGI.pm docs "perldoc CGI.pm". What way you do it 
depends on your style of coding all three mention will work just as  well. 
Since your already coding with  cgi-lib.pl  it should be an easy transision.

example in OOP:
use strict;
use CGI;
my $q = new CGI;

# make up the page

print $q->header(),
       $q->start_html(),
       $q->start_form    # equates to the form tag
       (
        -method=>"post"   # could  be post or get
        -action=>"http//your cgi script URL"
      )
,  
 $q->checkbox_group
     (
      -name=>'checkboxes',
     -values=>['$badiip ', 'badip'],
    -default=>[' badip1']
     )


that should get you started ,  you should pick up a book on cgi.pm or read the 
online docs. it's a verry powerfull modual I wouldn't want to work on CGI 
stuff without it it handles just about  everything .


Greg
       

      



Greg


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to