this is why I don't like CGI.pm

Discussion in 'Perl Misc' started by Mr P, Oct 5, 2011.

  1. Mr P

    Mr P Guest

    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!
     
    Mr P, Oct 5, 2011
    #1
    1. Advertising

  2. 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
     
    Jonathan N. Little, Oct 5, 2011
    #2
    1. Advertising

  3. Mr P

    Alan Curry Guest

    In article <>,
    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
     
    Alan Curry, Oct 5, 2011
    #3
  4. Mr P

    Guest

    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.
     
    , Oct 5, 2011
    #4
  5. >>>>> "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
     
    Randal L. Schwartz, Oct 6, 2011
    #5
  6. Mr P

    Justin C Guest

    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.
     
    Justin C, Oct 6, 2011
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dj Bass

    why Microsoft don't like frames...

    dj Bass, Jul 16, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    335
    Cowboy \(Gregory A. Beamer\)
    Jul 18, 2003
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    909
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,993
    Smokey Grindel
    Dec 2, 2006
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    477
    Patrick Kowalzick
    Mar 14, 2006
  5. excord80
    Replies:
    17
    Views:
    694
    J Kenneth King
    Jan 29, 2009
Loading...

Share This Page