[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cgi-list
Subject:    Re: [CGI] Checkbox
From:       "$Bill Luebkert" <dbe () wgn ! net>
Date:       2000-09-27 21:55:41
[Download RAW message or body]

Frederiko Costa wrote:
> 
> I re-wrote this script and send again.
> I have a form with 3 checkboxes. I would like to receive these values and
> return to the user your documents that they required. Each document have a
> price. Then when it returns the output to the user, plus the values to the
> user and return the total price. I need help. My script is returning
> something wrong.
> 
> Here is the form:
> 
> <form method=get action="/cgi-bin/secretv.pl">
> <input type=checkbox name=txt1 value=1>Historico<br>
> <input type=checkbox name=txt2 value=1>Declaracao<br>
> <input type=checkbox name=txt3 value=1>Outros<br>
> <input type=submit value="Enviar pedido">
> </form>
> 
> And here is the script:
> #!/usr/bin/perl
> 
> use CGI qw(:standard);
> 
> print "Content-type: text/html\n\n";
> 
> %documentos = ("txt1" => "10",
>                 "txt2" => "20",
>                 "txt3" => "30");
> 
> %guardanome = ("txt1" => "Historico Escolar",
>                 "txt2" => "Declaracao",
>                 "txt3" => "Outros");
> 
> $soma=0;
> 
> foreach $var (keys %documentos)
> {
>     if (param($var))
>     {
>       $aux=1;
>       push(@auxiliar,$guardanome{$var});
>       $soma+=$documentos{$var};
>   }
> }
> 
> if($aux==1) {

You have code embedded in string declaration here:

>     print qq|
>     <html><head><title>Requisicao de doc. on-line</title></head>
>     <body>
> 
>     <p><h2>Os documentos requisitados foram<br>
>     for($i=0;$i<=$#auxiliar;$i++) {
>     <li>$auxiliar[$i];
>     }
> 
>     <BR>
>     <p>O valor total do seu pedido foi de: R\$ $soma</p>
>     </li></h2></p></body></html>
>             |;
> }
> else
>   {
>   print qq|
>     <html><head><title>Requisicao de doc. on-line</title></head>
>     <body>
>      <p><h2>Vc nao solicitou nenhum documento<br>
> 
>     </li></h2></p></body></html>
>          |;
> }
> exit;

Try this and I recommend you always 'use strict;':

use strict;
use CGI qw(:standard);

print "Content-type: text/html\n\n";

my %documentos = ("txt1" => "10", "txt2" => "20", "txt3" => "30");
my %guardanome = ("txt1" => "Historico Escolar", "txt2" => "Declaracao", 
  "txt3" => "Outros");

my $soma = 0;
my $aux = 0;
my @auxiliar = ();

foreach my $var (keys %documentos) {

	if (param($var)) {

		$aux = 1;
		push (@auxiliar, $guardanome{$var});
		$soma += $documentos{$var};
	}
}

if ($aux == 1) {

	my $html = '';	# set up list here
	foreach (@auxiliar) {
		$html .= "<li>$_\n";
	}

	print <<EOD
<html><head><title>Requisicao de doc. on-line</title></head>
<body>

<p><h2>Os documentos requisitados foram<br>

$html

<BR>
<p>O valor total do seu pedido foi de: R\$ $soma</p>
</li></h2></p></body></html>
EOD

} else {

	print <<EOD;
<html><head><title>Requisicao de doc. on-line</title></head>
<body>
<p><h2>Vc nao solicitou nenhum documento<br>

</li></h2></p></body></html>
EOD

}

exit 0;

__END__



-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.wgn.net/~dbe/
  / ) /--<  o // //      Mailto:dbe@wgn.net   http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
-----------------------------------------------------------------
To unsubscribe, send mail to "majordomo@jann.com" with "unsubscribe cgi-list"
in the body.

CalendarPlus v3.0 with JavaPlus is available NOW!
http://www.calendarplus.com/

The CGI Tips & Tricks website (and archive of the list) is located
at http://perl.jann.com/
-----------------------------------------------------------------

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic