Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   this is why I don't like CGI.pm (http://www.velocityreviews.com/forums/t915248-this-is-why-i-dont-like-cgi-pm.html)

Mr P 10-05-2011 01:29 PM

this is why I don't like CGI.pm
 
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!


Jonathan N. Little 10-05-2011 02:53 PM

Re: this is why I don't like CGI.pm
 
Mr P wrote:
> 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...


--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

Alan Curry 10-05-2011 07:19 PM

Re: this is why I don't like CGI.pm
 
In article <82eaa1bc-7136-49cd-b2b6-38c75c658e9e@s9g2000yql.googlegroups.com>,
Mr P <misterperl@gmail.com> wrote:
>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.

--
Alan Curry

xhoster@gmail.com 10-05-2011 09:51 PM

Re: this is why I don't like CGI.pm
 
Mr P <misterperl@gmail.com> wrote:
> 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.

Randal L. Schwartz 10-06-2011 02:16 AM

Re: this is why I don't like CGI.pm
 
>>>>> "Alan" == Alan Curry <pacman@kosh.dhis.org> writes:

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

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion

Justin C 10-06-2011 10:03 AM

Re: this is why I don't like CGI.pm
 
On 2011-10-05, xhoster@gmail.com <xhoster@gmail.com> wrote:
>
> 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.

--
Justin C, by the sea.


All times are GMT. The time now is 07:14 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.