http://qs321.pair.com?node_id=602301


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:
    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.