Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-18 21:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found