Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > this is why I don't like CGI.pm

Reply
Thread Tools

this is why I don't like CGI.pm

 
 
Mr P
Guest
Posts: n/a
 
      10-05-2011
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!

 
Reply With Quote
 
 
 
 
Jonathan N. Little
Guest
Posts: n/a
 
      10-05-2011
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
 
Reply With Quote
 
 
 
 
Alan Curry
Guest
Posts: n/a
 
      10-05-2011
In article <82eaa1bc-7136-49cd-b2b6->,
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.


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
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      10-05-2011
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.


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.
 
Reply With Quote
 
Randal L. Schwartz
Guest
Posts: n/a
 
      10-06-2011
>>>>> "Alan" == Alan Curry <> 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
<> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
 
Reply With Quote
 
Justin C
Guest
Posts: n/a
 
      10-06-2011
On 2011-10-05, <> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
object-like macro used like function-like macro Patrick Kowalzick C++ 5 03-14-2006 03:30 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? sam@nospam.org Cisco 10 05-01-2005 08:49 AM
Why Why Why You HAVE NO IDEA MCSE 31 04-24-2004 06:40 PM



Advertisments