Let's say I have three .pl files (rpt1, rpt2, rpt3). I'm using HTML::Template and CGI.pm to generate the main menu. Clicking on the submit button will launch the rpt1.pl/rpt1.tmpl combo (via the POST method). From rpt1, I want to launch rpt2 depending on which cell is clicked. However, I'm having trouble snagging all the info I want. I also want to eventually create a link to each data cell that snatches the appropriate params and passes those to the next script. Note: not all the CGI params I want are in a form.

I have a "header section" in rpt1 that contains a bunch of info about the report. This header section is a separate H::T file that has been populated using various TMPL_VARs and CGI params. I'd like to snag that entire header section and have it repeat on the subsequent rpt 2 and rpt3 pages. I also need the various items in this header section to help determine what parameters to use in subsequent database calls for rpt2 and rpt3.

Now, I know I can put at the beginning of rpt2.pl the following type of statements for every variable I think I'll need in the subsequent pages, but this seems to be the "hard" way to do it (I'm thinking there should be an easier "get it all at once" way):

my $rpt_name = $CGI->param('rpt_name'); my $rpt_descr = $CGI->param('rpt_descr'); #etc., etc.
I've tried the following at various times trying to figure this out. I think I've managed to completely confuse myself. (Note: I didn't try these all at once; I tried them separately).

I can print out my variables like this, but I'm not sure how to then import them into the next script:

foreach my $name ( $CGI->param() ) { my $value = $CGI->param($name); print "The value of $name is $value<br>"; }
I tried to use CGI.pm's import_names in rpt2.pl, but nothing populates in the header template section as I would have expected (well, at least the CGI params, not necessarily the TMPL_VAR params):
$CGI->import_names('R'); #other stuff my $tmpl_main2 = HTML::Template->new( filename => "rpt2.tmpl", associate => $CGI, global_vars => 1, ); #other stuff print $tmpl_main2->output();
I've also tried this in rpt2.pl (that was launched from rpt1) but nothing prints out:
#!/usr/bin/perl use CGI ':standard'; print header(); print param('key');
And, from the CGI.pm docs, I've tried this in rpt1.pl, hoping that the "associate=>$CGI" in rpt2.pl would pull them in:
@names = $CGI->param;
I also (in desperation) tried passing the @names to the template like this but (as expected) I then get a complaint about 'passCGI' is not in my template. Even putting 'passCGI' in my template only led to further complaints about it should be a TMPL_LOOP, etc.
$tmpl_main1->param(passCGI => \@names);

I have searched quite a bit out in Google-land, and it seems like a lot of suggestions point to using the GET method, reading the ENV{QUERY_STRING}, parsing the stuff out, etc. However, my forms are using the POST method (but I'm not particular emotionally attached to that method... I just thought it was safer). Also, I wasn't thrilled about using hidden fields since that'll let someone view my source and see exactly what fields I'm passing around. And lastly, not all my variables are in forms.

So, since I know TIMTOWTDI, I thought I'd ask those folks who play with HTML::Template, CGI and Perl for ideas. Also, please feel free to dumb it down for me as I'm still learning this stuff. Thanks!

Lori


In reply to HTML::Template, CGI, pass template params to next script by Lori713

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.