Dear Monks
I'm fairly new to perl CGI, and am trying to write a simple cgi based calendar. I've run into a problem trying to update the value of a hidden field in a self-referring url. Here's a minimal example:
#!/usr/bin/perl use strict; use warnings; use LWP::Simple; use CGI; use CGI::Carp qw(fatalsToBrowser); my $q = new CGI; print $q->header; print $q->start_html; my $serverRoot = "$ENV{SERVER_NAME}"; my $previousTotal = $q->param('sumTotal'); print $q -> h2("Previous Total: $previousTotal<br>"); my $currentTotal = $previousTotal + 2; print $q -> h2("Current Total: $currentTotal<br>"); print $q -> start_form( -name => 'addition', -method => 'GET', -enctype => &CGI::URL_ENCODED, -action => "http://$serverRoot/cgi-bin/sum.cgi" # <-se +lf url; ); print $q -> hidden( -name => 'sumTotal', -value => "$currentTotal" ); print $q->submit( -name => 'button', -value => 'Add 2', ); print $q ->end_form; print $q ->end_html;
I thought that each time the button is pressed, the value of $currentTotal should increase by 2. After pressing the button once, $currentTotal increases to 4, but when the button is pressed again, -sumTotal is still set to 2 in the url, and not 4 as I expected.
If anyone could explain why, or direct me towards an answer, I'd be very grateful!
Thanks in advance
Michael| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |