Hey everyone

I have been working on a small CGI script lately, and things have been going well. However, I have come up against a sort of problem.

My main goal so far of this "project" is to simply: Retrieve data from MySQL via the DBI module -> display this data in HTML form -> make a form for someone to input a row in the MySQL DB -> display contents of DB again in HTML form.

So far, everything but one of those parts of the project so far are completed. The part I don't know how to do yet is the form part. I am using HTML::Template for all of the HTML part, and am not sure how I can use a form with this (since I don't want to mirror too many cases or loops in the template that could have been done in the acutal .pl/.cgi program.

I did take a long look at this node: Q / A and HTML::Template techniques... and got some ideas as to how to do this *kind of*. But I don't know quite where to go with the code I have come up with which is displayed here:
#!/usr/bin/perl -w use strict; use HTML::Template; use CGI; use CGI::Carp qw(fatalsToBrowser); my $cgi = new CGI; print $cgi->header; my $template = new HTML::Template(filename => "1.tmpl", die_on_bad_par +ams => 0); $template->param( BOX => $cgi->popup_menu(-name=>'color', -values=>['red','green','blue','chartreuse'] +), BOX2 => $cgi->textfield('name'), ); print $template->output();

Also here is the .tmpl file:
<html> <title>test</title> <body> <form> <table border=1 > <tr> <td> Color1: <TMPL_VAR NAME="BOX"> <br></td> <td> What is your name?: <TMPL_VAR NAME="BOX2"> <br> </td> <td> <input type=submit> </td> </table> </form> </body> </html>

Hopefully my question(s) are clear enough to answer, or at least to point to where I can find out how to do it in a correct manner. Thanks for any and all help or comments regarding this question!

Andy Summers

In reply to HTML::Template Form Usage by bladx

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.