this is why I don't like CGI.pm

M

Mr P

I created a checkbox with $cgi->checkbox() . It showed up fine, I can
label it, etc. But it WILL NOT CHECK on instantiation. I tried -
checked => 1, -checked => "checked", -selected => "1", -selected => 1,
-on => 1, etc etc.

Oddly, if I change the NAME of the box, *sometimes* it checks. If I
add an X to the front it will check, if I add a 2 to the end, it
won't. Although this isn't repeatable.

Mozilla current rev, Perl 5.8.8

Its definitely NOT a Mozilla issue- the page source is missing the
checked="checked"
This is why adding a CGI;pm layer is nightmarish. It's ever so much
easier to just PRINT the HTML.

I even asked my officemate to look at the code, and like me, he just
scratched his head and walked off muttering about WHY DO WE HAVE TO
USE CGI.PM ??

I hosed around with this problem like 3 hours, eventually gave up,
and wrote my own check. I generate the checkbox line with cgi.pm, then
perform a:

s/( value)/ checked="checked"$1/

Its wacked that I had to do this...


Thanks, CGI.pm like had an extra 4 hours to waste this week!
 
J

Jonathan N. Little

Mr said:
I created a checkbox with $cgi->checkbox() . It showed up fine, I can
label it, etc. But it WILL NOT CHECK on instantiation. I tried -
checked => 1, -checked => "checked", -selected => "1", -selected => 1,
-on => 1, etc etc.

Oddly, if I change the NAME of the box, *sometimes* it checks. If I
add an X to the front it will check, if I add a 2 to the end, it
won't. Although this isn't repeatable.

Mozilla current rev, Perl 5.8.8

Its definitely NOT a Mozilla issue- the page source is missing the
checked="checked"
This is why adding a CGI;pm layer is nightmarish. It's ever so much
easier to just PRINT the HTML.

I even asked my officemate to look at the code, and like me, he just
scratched his head and walked off muttering about WHY DO WE HAVE TO
USE CGI.PM ??

I hosed around with this problem like 3 hours, eventually gave up,
and wrote my own check. I generate the checkbox line with cgi.pm, then
perform a:

s/( value)/ checked="checked"$1/

Its wacked that I had to do this...


Thanks, CGI.pm like had an extra 4 hours to waste this week!

The example in the manual works right out of the box:

print checkbox(-name=>'checkbox_name',
-checked=>1,
-value=>'ON',
-label=>'CLICK ME');

your error maybe elsewhere in your code...
 
A

Alan Curry

I created a checkbox with $cgi->checkbox() . It showed up fine, I can
label it, etc. But it WILL NOT CHECK on instantiation. I tried -
checked => 1, -checked => "checked", -selected => "1", -selected => 1,
-on => 1, etc etc.

Oddly, if I change the NAME of the box, *sometimes* it checks. If I
add an X to the front it will check, if I add a 2 to the end, it
won't. Although this isn't repeatable.

The same thing happened to me. I eventually figured out that if you use the
same object to parse an HTTP request and write an HTML form, it assumes that
fields with the same name in both are supposed to be linked, and copies the
values from the request into the form, ignoring the values you told it to put
there.

I hated this feature too. Too much spooky behind-the-scenes action based on a
completely unwarranted assumption.
 
X

xhoster

Mr P said:
I created a checkbox with $cgi->checkbox() . It showed up fine, I can
label it, etc. But it WILL NOT CHECK on instantiation. I tried -
checked => 1, -checked => "checked", -selected => "1", -selected => 1,
-on => 1, etc etc.

You are probably getting tripped up by "sticky fields". They make good
sense once you get around to reading that part of the documentation. It
also tells you how to override them.


Thanks, CGI.pm like had an extra 4 hours to waste this week!

I too often find that 4 hours of randomly flailing about and swearing will
often save me from 20 minutes of reading the documentation.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
R

Randal L. Schwartz

Alan> The same thing happened to me. I eventually figured out that if
Alan> you use the same object to parse an HTTP request and write an HTML
Alan> form, it assumes that fields with the same name in both are
Alan> supposed to be linked, and copies the values from the request into
Alan> the form, ignoring the values you told it to put there.

This is called "sticky fields". It's (a) documented, (b) useful *most*
of the time, and (c) possible to disable.

Alan> I hated this feature too. Too much spooky behind-the-scenes action
Alan> based on a completely unwarranted assumption.

No, the assumption makes sense for the early CGI-only web. And changing
it now would break too many things needlessly.

print "Just another Perl hacker,"; # the original
 
J

Justin C

I too often find that 4 hours of randomly flailing about and swearing will
often save me from 20 minutes of reading the documentation.

Xho's law? It catches me too many times, "That didn't work, oh, it must
be .... nope, how about ..." say bye-bye to time.

Justin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top