...But I don't know quite where to go with the code I have come up with which is displayed here:
I'm guessing that being told to use HTML::Template isn't exactly what you're looking for here, although it's very good advice.
If you're looking for advice on what to do to your code from
here, such that you can do the DBI lookup, show the table
entries and then offer an addition form then you might do
the following:
tmpl file
I'm sure you can edit your cgi code appropriately to fill in that loop. Abstracting the html around the loop into your template file allows you to later change the back-grounds of your table rows or data or their fonts or many other things without having to wade through your code again. Of course if you don't like HTML source, you might not realise the benefit of this today.<html> <title>test</title> <body> <TMPL_IF NAME=data> Your row was added in successfully.<p> </TMPL_IF> <h1>Data already in table</h1> <table> <TMPL_LOOP NAME=data> <tr> <td>Name:</td><td><TMPL_VAR NAME=box2></td> <td>Colour1:</td><td><TMPL_VAR NAME=box></td> </tr> </TMPL_LOOP> </table> <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>
Whether or not this duplicates loops depends on your code. If you do a query, then loop through all the results pushing the hashrefs you've fetched into an array and then give that to the template to loop through and display you've duplicated a loop. Perhaps you'd think it better to build your table inside your CGI code and then add that to a variable which you then display.
HTML::Template purists will hate that idea, and they should, because you'd be perverting a very powerful and beautiful tool, but if it's the best solution you have, then use it. Then again, I'd encourage you not to be afraid of having two similar loops here (using TMPL_IF to replace possible null fields with   might also help).
Jacinta
In reply to Re: HTML::Template Form Usage
by jarich
in thread HTML::Template Form Usage
by bladx
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |