in reply to Re: Re: HTML and CGI coding
in thread HTML and CGI coding

Hello: Well, I never realized that trying to change a font color, size, and face was going to cause so much controversy...:) Anyway, I've been modifiying my code and right now it looks as such, I included the whole section of code so you can see what's happening:
push (@row, Tr ({"-align" => "CENTER", "-valign" => "TOP", "-BGCOLOR" => "blue", "-font-color" => "yellow", "-FONT-FAMILY" => "verdana, +arial,helvetica", "-FONT-SIZE" => "12"}, + th ("I +tem"), th ("Quantity"), th ("Description"), th ("Unit Price"), th ("Price") )); foreach my $item_id (sort (keys (%{$cart_ref}))) { my $item_ref = $cart_ref->{$item_id}; my $total_item_price = $item_ref->{qty} * $item_ref->{price}; $total_price += $total_item_price; # generate a link allowing the item to be deleted from the car +t my $url = sprintf ("%s?choice=delete;item_id=%s", url (), escape ($item_id)); push (@row, Tr ( td (escapeHTML ($item_id)), td (escapeHTML ($item_ref->{qty})), td (escapeHTML ($item_ref->{description})), td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $item_ref->{price +}))), td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $total_item_price +))), + ($show_links ? td (a ({-href => $url}, img ({-src => "../im +ages/delete.jpg", -border => "0"}))) + : td (" ")) )); } push (@row, Tr ( td ({-colspan => "2"}, ""), td ({-colspan => "2"}, "Total"), td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $total_price))) )); return (table ({-border => 0}, @row)); }
Now, I believe I've incorporated lots of the suggestions but my row with headings have the blue background but it still doesn't want to take the new font color, size, or face. At least I'm not getting any error messages. Any other thoughts are greatly appreciated.

Replies are listed 'Best First'.
Re: Re: Re: Re: HTML and CGI coding
by pfaut (Priest) on Dec 09, 2002 at 16:15 UTC

    As I stated before, I think you'd be much better off learning and using CSS for your markup than trying to do it with CGI. You'll get much more consistent results and changes will be a lot easier to make since you'll only have to change one thing in a style sheet rather than who knows how many things in your perl program. Alternately, look into producing your HTML output with HTML::Template rather than CGI. That method would also separate your presentation from your program logic.

      Hi! Unfortunately, I'm not familiar with either CSS or HTML::Template. I'll look into it but I'm not sure where to start.
        Whether or not HMTL::Template is a better choice than CGI.pm is really up to you, but definetly look into CSS! In the meantime, here is a watered down version of your problem that uses HTML::Template instead (be sure and check out our HTML::Template Tutorial for some lessons on the basics).
        use strict; use CGI qw(header); use HTML::Template; my $cart_ref = { 42 => { qty => 5, price => 5, description => 'widget 42', }, 77 => { qty => 2, price => 7, description => 'widget 77', }, }; my $html = do {local $/;<DATA>}; my $tmpl = HTML::Template->new(scalarref=> \$html); my $rows = [ map { { id => $_, %{$cart_ref->{$_}} } } keys %$cart_ref ]; $tmpl->param(rows => $rows); print header, $tmpl->output; __DATA__ <table> <tr> <th>Item</th> <th>Quantity</th> <th>Description</th> <th>Price</th> </tr> <tmpl_loop rows> <tr> <td><tmpl_var id></td> <td><tmpl_var qty></td> <td><tmpl_var description></td> <td><tmpl_var price></td> </tr> </tmpl_loop> </table>

        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: Re: Re: Re: HTML and CGI coding
by thinker (Parson) on Dec 09, 2002 at 15:24 UTC
    Hi hbradshaw,

    as I pointed out in my earlier post, you should choose either
    Tr( -attr => "value", "-foo-bar" => "baz" )

    ie, attributes have leading hyphens, are quoted if contain inline hyphens, and are not surrounded by {} brackets,
    or
    Tr({ attr => "value", "foo-bar" => "baz" })

    ie, attributes have no leading hyphen, but are contained within {} brackets, making it an anonymous hash. Strings with inline hyphens should still be quoted

    The easiest way to fix your code above is to remove the {} brackets from within your Tr().

    hope this helps

    thinker
Re: Re: Re: Re: HTML and CGI coding
by demerphq (Chancellor) on Dec 09, 2002 at 15:46 UTC
    Hi hbradshaw, im afraid my involvement in this thread is restircted to the quoting of hash keys. There are others far more able to advise you on the correct uage of CGI than I am.

    Good luck however, and a little thought, you may find perltidy from sourceforge (dont have a link handy sorry) to be a useful addition to your tool kit.

    Regards,

    --- demerphq
    my friends call me, usually because I'm late....