For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > CGI bug









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author CGI bug
Jeremy Kister

2006-10-05, 6:58 pm

Using an older (unknown version) and brand new (3.25) CGI, I have been
able to demonstrate a simple bug:

use strict;
use CGI qw(:standard);

my $q = new CGI();

my $x = $q->param('x');
my $y = ($x + 1);

print $q->header(), $q->start_html(),
$q->hidden('x',$y), "\n",
$q->hidden('a',$y), "\n",
$q->end_html();


using script.pl?x=5, you'll see that the cgi prints x=5 but a=6

apparently only happens when you're setting a parameter via 'hidden'
that was read by 'param'


--

Jeremy Kister
http://jeremy.kister.net./
usenet@DavidFilmer.com

2006-10-05, 6:58 pm

Jeremy Kister wrote:
> $q->hidden('x',$y), "\n",


It's not a bug. That is a sticky little situation (because form
elements are sticky by default).

Consider:
$q->hidden({-force => 1, name => 'x', value =>$y}), "\n",

--
David Filmer (http://DavidFilmer.com)

John W. Krahn

2006-10-05, 6:58 pm

Jeremy Kister wrote:
> Using an older (unknown version) and brand new (3.25) CGI, I have been
> able to demonstrate a simple bug:


There is a beginners-cgi list that deals with Perl and CGI issues:
http://lists.cpan.org/showlist.cgi?name=beginners-cgi

And if you are reporting a bug in CGI:

perldoc CGI
[ snip ]
AUTHOR INFORMATION
Copyright 1995-1998, Lincoln D. Stein. All rights reserved.

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

Address bug reports and comments to: lstein@cshl.org. When sending bug
reports, please provide the version of CGI.pm, the version of Perl, the
name and version of your Web server, and the name and version of the
operating system you are using. If the problem is even remotely
browser dependent, please provide information about the affected
browers as well.



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
Rob Dixon

2006-10-05, 6:58 pm

Jeremy Kister wrote:
>
> Using an older (unknown version) and brand new (3.25) CGI, I have been
> able to demonstrate a simple bug:
>
> use strict;
> use CGI qw(:standard);
>
> my $q = new CGI();
>
> my $x = $q->param('x');
> my $y = ($x + 1);
>
> print $q->header(), $q->start_html(),
> $q->hidden('x',$y), "\n",
> $q->hidden('a',$y), "\n",
> $q->end_html();
>
>
> using script.pl?x=5, you'll see that the cgi prints x=5 but a=6
>
> apparently only happens when you're setting a parameter via 'hidden'
> that was read by 'param'


No. It's the designed behaviour. The CGI documentation says this:

Note, that just like all the other form elements, the value of a hidden
field is "sticky". If you want to replace a hidden field with some other
values after the script has been called once you'll have to do it
manually:

param('hidden_name','new','values','here
');

The idea is that if a script both receives and displays form input then it is
probably redisplaying the same form, and it would be a shame to throw away the
input that the operator had already typed in.

It's also nothing to do with hidden values and param method calls. Try this:

use strict;
use CGI qw(:standard);

my $q = new CGI( {x => 5} );

print $q->header(),
$q->start_html(),
$q->textfield('x',6), "\n",
$q->textfield('a',6), "\n",
$q->end_html();

and you'll see it has the same result.

Oh, and I wonder if you were asking for help, which is what this list is for, or
just trumpeting that thought you'd discovered an error in someone else's work?

Anyway, I hope this helps.

Rob
W.P.Nijhof

2006-10-06, 3:57 am

Rob Dixon wrote:
> values after the script has been called once you'll have to do it
> manually:
>
> param('hidden_name','new','values','here
');
>

You can also do this:

$q->hidden( -name=>'x', -value=>$x, -override=>1 )

WayPay

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com