Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This is more of a 'how can this be done', 'do you have any better ideas' post than anything else. I have pretty basic (not to mention ugly), forms/tables being printed (see example). I want to know how now begin working on the appearance of the tables and make them a lot more neat. You know, better alignment, background colors, the whole works.

Is there a different way to go at it rather than what's shown below? Are there form/table templates for us to use somewhere?

Thanks.

print start_form(), table( Tr( td("Name: "), td( textfield( -name => 'name', -default =>"$edituser", -size => 40 ) ) ), Tr( td("Address 1: "), td( textfield( -name => 'add1', -default =>"$add1", -size => 40 ) ) ), Tr( td("Address 2: "), td( textfield( -name => 'add2', -default =>"$add2", -size => 40 ) ) ), Tr( td("City/State: "), td( textfield( -name => 'city', -default =>"$city", -size => 40 ) ) ), Tr( td("Zip: "), td( textfield( -name => 'zip', -default =>"$zip", -size => 40 ) ) ), Tr( td("Country: "), td( textfield( -name => 'country', -default =>"$country", -size => 40 ) ) ), Tr( td(), td(submit('update')) ), ), end_form(),;

Replies are listed 'Best First'.
Re: Beautifying CGI.pm forms/tables
by b10m (Vicar) on Dec 27, 2003 at 12:46 UTC
Re: Beautifying CGI.pm forms/tables
by thens (Scribe) on Dec 27, 2003 at 16:03 UTC
Re: Beautifying CGI.pm forms/tables
by jeffa (Bishop) on Dec 27, 2003 at 18:33 UTC

    "Are there form/table templates for us to use somewhere?"

    I usually just make them myself. You really need to sit down and design just how general you want to make your templates. YMMV. Here is an example i came up with for this problem using Template. If you have it installed, just save the following to a file and run tpage on it.

    [% USE CGI %] [% elements = [ { label = 'Name:' name = 'name' } { label = 'Address 1:' name = 'address1' } { label = 'Address 2:' name = 'address2' } { label = 'City/State:' name = 'city' } { label = 'Country:' name = 'country' } { label = 'Zipcode:' name = 'zip' } ] %] [% BLOCK row %] <tr> <td align="right">[% label %]</td> <td align="left"> [% CGI.textfield({Name => name Size => 40}) %] </td> </tr> [% END %] <form> <table width="50%"> [% FOREACH e = elements %] [% PROCESS row label = e.label name = e.name %] [% END %] </table> [% CGI.submit('update') %] </form>

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Beautifying CGI.pm forms/tables
by pg (Canon) on Dec 27, 2003 at 16:34 UTC

    Add on top of what b10m have already said, CGI.pm actually allows you to define style for a component on fly. This is one line I cut from one of my scripts:

    $msg .= $cgi->table({-border => 1, bgcolor => $c1, style => "Color +: $c2;"}, $cgi->Tr($table_data));

    Pay attention to that style => "Color: $c2;", is it not very handy?.