I changed this perl program to have dynamic dropdowns instead of static. It's working, except I need the other form data to be saved whilst they're messin with the drop downs. I'm using HTML::Template. I won't include the template files as they're just basic HTML with TMPL_VAR's. There's 3 template files. 1 is the form, the 2nd for email, 3rd is the confirm screen. So, i was thinking of somehow combining my formparams sub and my getBody sub. I know this could be cleaned up a lot, but i'd like to just getting it working first. UPDATE: I could just manually add something like this to my forparams:
$formparams{FIRSTNAME} = $query->param("firstname");
my $query = new CGI; my %db_hash; my $s_dept = $query->param("s_dept"); my $dept_name=&build_list("D", "",$s_dept); my @dept_loop = @tmp_hash; my @branch_loop; my $branch_name; if ($s_dept = $query->param("s_dept")) { my $s_branch = $query->param("s_branch"); $branch_name=&build_list("B", "AND PARENT_ID = $s_dept",$s_branch); @branch_loop = @tmp_hash; } my @div_loop; my $div_name; if ($s_branch = $query->param("s_branch")) { if ($s_branch != "Choose Branch") { my $s_div = $query->param("s_div"); $div_name=&build_list( "V", "AND PARENT_ID = $s_branch",$s_div) +; @div_loop = @tmp_hash; } } if ($final_sub = $query->param("final_sub")) { # submit and proces +s the form (including send email) &processForm(); exit; } &formparams(); &createForm($formTemplate); exit; #=================================================== # build drop downs #=================================================== sub build_list () { my ($org_type,$sql_insert,$selected)=@_; #receive variable int +o subroutine my %isSelect; $isSelect{$selected}="SELECTED"; my $dbh=DBI->connect('DBI:Oracle:METAD1', 'ei_arf_webform_select' +, 'metad1') or die "Cannot connect to DB: " . DBI->errstr; my $sql = "SELECT org_id,org_name FROM mv_org_structure_list WHERE ORG_TYPE='$org_type' $sql_insert ORDER BY org_na +me ASC"; my $sth = $dbh->prepare($sql) || print "Cannot prepare"; $sth->execute || print "Cannot execute"; my @result; %db_hash = (); while (@result = $sth->fetchrow_array()) { $db_hash {$result[0]} = $result[1]; } @tmp_hash = (); foreach my $key (keys %db_hash) { push @tmp_hash, {ORG_ID => $key, ORG_NAME => $db_hash{$key}, O +RG_SELECT => $isSelect{$key}}; } return $db_hash{$selected}; } #=================================================== # forparams #=================================================== sub formparams () { %formparams = (); $formparams{LOGO} = "/images/logobw.gif"; $formparams{TITLE} = "ARF Exempt Request (Network and/or E-Mai +l Account, Voicemail, Telephone Re-assignment)"; $formparams{PATH} = $ENV{SCRIPT_NAME}; $formparams{DEPARTMENT} = \@dept_loop; $formparams{BRANCH} = \@branch_loop; $formparams{DIVISION} = \@div_loop; } #===================================== # create new form from html template #===================================== sub createForm { $formTemplate = new HTML::Template( filename => $FORM_TMPL_FILE ); for my $key (keys %formparams) { $formTemplate->param($key => $formparams{"$key"}); } my ($formTemplate) = @_; print $formTemplate->output; return; } #===================================== # process submit request #===================================== sub processForm { my $body; $body = getbody(); my $email_subject = "EDS/Telecom Action"; &sendMail ($smtp, $to, $cc, $from, $email_subject, $body); print "<br>"; print "Thank you! <br/>"; print "<br>"; print "Your request has been submitted.<br><br>"; print "<a href=\"javascript:window.close();\">Close Window</a>\n"; return; } #================================================== # get email body set for specific body requirement #================================================== sub getbody() { my $resulttemplate = new HTML::Template( filename => $RESULTS_TMPL +_FILE ); my $displaytemplate = new HTML::Template( filename => $DISPLAY_TMP +L_FILE ); my $params = getdata(); $resulttemplate->param(FIRSTNAME => $params->{'firstname'}); $resulttemplate->param(LASTNAME => $params->{'lastname'}); #bunch of other parmas removed, you get the idea # To return a list of parameters in the template of $displaytemplate ( +keys) my @parameter_names = $displaytemplate->param(); foreach my $name (@parameter_names) { # Assign the value of $resulttemplate to the key of $displayte +mplate # Since the keys have the same name in both templates. $displaytemplate->param($name => $resulttemplate->param($name)) +; } $body = $resulttemplate->output; if ($body) { print $displaytemplate->output; # Print out form data to s +creen return $body; # Returns form data to +be sent by email } else { print "Error: Cannot send email body to send<br>"; exit; } } #======================================= # Get CGI data from the form submitting #======================================= sub getdata() { my %params; my $query = new CGI; foreach my $key ($query->param) { $params{$key} = $query->param($key); } return \%params; } #===================================== sub sendMail { # SEND EMAIL... BLAH BLAH return; }

In reply to save form data/combine subs by djbryson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.