Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: HTML::Template recalling selected dropdown options

by Hero Zzyzzx (Curate)
on May 12, 2005 at 03:01 UTC ( #456218=note: print w/ replies, xml ) Need Help??


in reply to HTML::Template recalling selected dropdown options

The HTML form generation features of CGI will save your butt here, the popup_menu() method will remember the last selected value by default. The "sticky value" behavior is very cool.

my $menu=$q->popup_menu( -name=>"templates", -id=>"templates", -values=>["",23,36], -labels=>{""=>"Select . . .",23=>"Text One",36=>"Text Two" +} );

You should also check out CGI::FormBuilder, which can automate a whole slew of form generation stuff, and use HTML::Template for output control.

-Any sufficiently advanced technology is
indistinguishable from doubletalk.

My Biz


Comment on Re: HTML::Template recalling selected dropdown options
Download Code
Re^2: HTML::Template recalling selected dropdown options
by bradcathey (Prior) on May 12, 2005 at 12:24 UTC

    Thanks, I did consider this, but I have this "thing" about keeping as much of the HTML as possible on the HTML side (but even Sam himself doesn't have this hang-up, and I quote from the H::T doc:

    "To some people this smacks of mixing HTML and code in a way that they hoped HTML::Template would help them avoid. To them Iíd say that HTML is a violation of the principle of separating design from programming. Thereís no clear separation between the programmatic elements of the <form> tags and the layout of the <form> tags. Youíll have to draw the line somewhere - clearly the designer canít be entirely in charge of form creation. Itís a balancing act and you have to weigh the pros and cons on each side. It is certainly possible to produce a <select> element entirely inside the template. What you end up with is a ratís nest of loops and conditionals. Alternately you can give up a certain amount of flexibility in return for vastly simplifying your templates. I generally choose the latter."

    I guess if popup_menu() can help me avoid the mess of javascript/html/Perl then it might be worth a closer look.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

      popup_menu() (and checkbox_group(), radio_group(), etc) can absolutely simplify your templates, on large forms you'll see a huge difference. Personally I haven't often had the need to edit form fields directly as HTML, because you can apply a class to the field and change much of it's appearance with CSS. Most field options are created off database queries, seldom are select/radio/check lists hardcoded.

      I only use CGI.pm to parse values, print headers, handle uploads and create HTML Forms (though I've started to use CGI::FormBuilder for most of my forms). On trivial apps I'll use the HTML generation features, too. For me, I think this is CGI.pm's "highest and best" use- the tricky stuff that doesn't usually impact design is handled by a library that does it EXTREMELY well.

      The way I think of it- you can absolutely save yourself time generating the HTML form fields with CGI, and in those cases where you just can't because of some design problem (which is pretty rare, in my experience), you can always fall back to manual form element generation. In the meantime, you've still come out ahead, with smart forms and saved effort.

      -Any sufficiently advanced technology is
      indistinguishable from doubletalk.

      My Biz

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://456218]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-09-23 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (217 votes), past polls