mtmcc has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl CGI: updating hidden field values for self-referring url
by Your Mother (Archbishop) on Feb 17, 2014 at 19:35 UTC | |
by choroba (Cardinal) on Feb 17, 2014 at 19:54 UTC | |
by Your Mother (Archbishop) on Feb 17, 2014 at 20:13 UTC | |
by Anonymous Monk on Feb 18, 2014 at 00:44 UTC | |
|
Re: perl CGI: updating hidden field values for self-referring url
by tangent (Parson) on Feb 17, 2014 at 19:24 UTC | |
|
Re: perl CGI: updating hidden field values for self-referring url
by mtmcc (Hermit) on Feb 17, 2014 at 20:14 UTC |