Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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.

Replies are listed 'Best First'.
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:
    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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-10-20 13:11 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (81 votes). Check out past polls.