Dear Monastic Masters ...

I am rather new to TT2. I am attempting to pass CGI params back and forth between a template and a CGI script. The script is being used to process the same form (TT) under slightly different conditions. I am passing "flags" (parameters) via CGI.pm from the script and then back via HTML hidden input. The info in the flags is not sensitive.

When a user clicks a link, my CGI is launched (lets call it login.cgi). At this stage, the CGI simply presents an empty form that is generated by a template using TT2. The query string includes my "flag" parameters:

print "Location: http://$base_url/cgi-bin/login.cgi?uid=$uid&aflag=$af +lag&sflag=$sflag\n\n";

This fires the script and a small template file that gets embedded into a larger page via the content directive. This part works great. At this stage, all of my information is getting passed to form perfectly.

Now the user adds some data to the form, and this is where I run into problems. Here is the information that I'm passing the template from the CGI script:

my $vars; my $requid = $cgi -> param('uid'); my $aflag = $cgi -> param('aflag'); my $sflag = $cgi -> param('sflag'); # dynamic page generation (first time entry) if ($cgi -> param('first_launch') ne 'false') { $vars = { base_url => $base_url, requid => $uid, aflag => $aflag, sflag => $sflag, }; my $template = 'login.tt'; print $cgi -> header; $tt -> process($template, $vars) || die $tt -> error(); exit; };

The template looks like this:

<tr class="row_config_white"> <td colspan="2" align="center" height="200"> <form name="login_form" method="post" action="[% base_ +url %]/cgi-bin/login.cgi"><br> <h2>Login</h2><br> <font color="red">[% error_message %]</font><b +r><br> Email Address:&nbsp;<input type="text" name="e +mail" size="30" value="[% email %]"><br><br><br> Password:&nbsp;<input type="password" name="pa +ssword" size="20"><br><br><br> <input type="hidden" name="first_launch" value +="false"> <input type="hidden" name="uid" value="[% uid +%]"> <input type="hidden" name="aflag" value="[% af +lag %]"> <input type="hidden" name="sflag" value="[% sf +lag %]"> <input type="submit" value="Login"><br><br><br +> </form> </td> </tr> <tr class="row_config_white"> <td colspan="2" align="center" height="20"> <a href="[% base_url %]/cgi-bin/forgot_pw.cgi">Forgot +Password</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="[% base_url + %]/cgi-bin/request_account.cgi">Create New User account</a> </td> </tr>

At this stage, the user will attempt to enter his/her login. They click submit and the form info is passed back to the same CGI. This time, however, the "first time entry" portion of the script is ignored because the hidden input has set first_launch to false.

If this is bypassed program control goes on its merry way to check the form and then process it.

If I remove sflag from $vars (where it is passed to the template from the CGI), the program behaves. However, the moment I insert it, all of the CGI params are lost and I'm stuck in the entry area of the page forever. I must be doing something wrong with sflag, but I just can't see it. Any help would be greatly appreciated!

Thanks!


In reply to Problem Passing Param Between Template Toolkit & CGI by Perobl

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.