Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: altering existing form

by ptum (Priest)
on Feb 27, 2007 at 15:03 UTC ( #602301=note: print w/ replies, xml ) Need Help??


in reply to altering existing form

Your question isn't really very clear, but it sounds like you have an existing textfield that you want to change to be a popup menu, and you want to populate that menu with the contents of your department list.

Somewhere, probably in the form template that you didn't show us, you have a textfield definition containing HTML like that which could be produced by this code:

my $dept_control = $cgi->textfield(-name=>"dept", -size=>12, -maxlength=>12, -default=>$some_default_value);

You want to change that textfield to a popup menu, maybe like this:

my $dept_control = $cgi->popup_menu(-name=>"dept", -values=>\@dept);

Update: I'm not sure how to create complex form controls using HTML::Template -- usually I create 'em up front using CGI and then I pass the fully-constructed controls to the template as a TMPL_VAR. You might want to have a look at the docs for CGI.


Comment on Re: altering existing form
Select or Download Code
Re^2: altering existing form
by djbryson (Beadle) on Feb 27, 2007 at 15:07 UTC
    Correct form.tmpl is just HTML and has:
    <input type=text name="dept" size=30>
    display.tmpl has:
    <strong>Department: </strong><TMPL_VAR NAME=DEPARTMENT><BR>
    body.tmpl has:
    Department: <TMPL_VAR NAME=DEPARTMENT>
    UPDATE
    I think I just need to add DEPT in %formparams, it's contents will be the @dept, and in the form.tmpl stick in
    <select name="dept"><TMPL_VAR NAME=DEPT></select> Gonna try that...
      In that case, you want to replace the aforementioned <input> element in form.tmpl with a <select> element with an HTML::Template loop inside it:
      <select name="dept"> <TMPL_LOOP NAME="DEPT_LOOP"> <option value="<TMPL_VAR NAME="DEPT">"><TMPL_VAR NAME="DEPT"> </TMPL_LOOP> </select>
      Then, from within your script, you want to select all possible departments from your database, and populate that list using the loop name (DEPT_LOOP in the example). For more info on how to do that, see the HTML::Template docs.

      __________
      Systems development is like banging your head against a wall...
      It's usually very painful, but if you're persistent, you'll get through it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-07-06 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls