brysonic venture has asked for the wisdom of the Perl Monks concerning the following question:

Half the problem with programming is formatting, I want to arrange 9 buttons (CGI generated)) accross the top of a page along with the title. This is very easy to do with HTML but am having a problem getting it done with CGI. thought of using a table, but none of my attempts have worked? Any ideas oh swami thx, brysonic

Replies are listed 'Best First'.
Re: Formatting CGI
by chromatic (Archbishop) on Apr 06, 2000 at 21:43 UTC
    Well... your (CGI|Perl) script will have to output HTML or something the client will understand anyway. Most simple Perl web scripts I see do something like:
    print STDOUT >>EOT; <table> <tr> <td>FIRST BUTTON</td> <td>SECOND BUTTON</td> <td>THIRD BUTTON</td> </tr> <tr> <td>I AM ON THE SECOND ROW</td> <td>YOU ARE LISTENING TO ME TYPE</td> <td>MY NAME IS MORT</td> </tr> </table> EOT
    So really, it's a matter of doing both. (Note that CGI.pm provides a bevy of methods for generating HTML for you. There are also nice things like Text::Template and HTML::Mason. In a simple case, there's nothing wrong with using a here doc and embedding your HTML in the script. Just don't use a page full of print statements.)
      I don't have any problems doing it with html, its a matter of getting the CGI to output it ie.. (This does not work)
      #!/usr/bin/perl use CGI qw/:standard :html3/; print header, start_html("Soft Bug Buddy"), $action = param('action'); print_bugform(); sub print_bugform { print start_form; print table({-border=>''}, Tr({-align=>CENTER, -valign=>TOP}, [ th([ print submit(-name=>'action',-value=>'whatever'), print submit(-name=>'action',-value=>'whomever'), print submit(-name=>'action',-value=>'wherever'), 'Some kind of text', print submit(-name=>'action',-value=>'quit') ]) ] )); }
      thx again,
        It doesn't work right because you shouldn't be print-ing the submit buttons; the submit method (as well as the other HTML methods in CGI.pm) *returns* the HTML, so you should just take the print statements out, and it should work just fine.
        th([ submit(-name=>'action', -value=>'whatever'),
        and so on.

        By the way, you don't *have* to use the CGI.pm methods if you don't want to, or if you're more comfortable just printing out HTML. Personally, I've never found much of a use for them.

        As Abigail wrote: "CGI.pm's set of methods that output html tags seems to me as useful as an English.pm module with a method for every word, and using that instead of writing plain text."

Re: Formatting CGI
by comatose (Monk) on Apr 06, 2000 at 23:08 UTC

    Or to be more specific ($query is your CGI object):

    print STDOUT <<EOT; <p>Some more html...</p> <table> <tr> EOT print '<td>' . $query->submit(-name=>'Button1', -value=>'Button1') . ' +</td>'; print '<td>' . $query->submit(-name=>'Button1', -value=>'Button1') . ' +</td>'; print '<td>' . $query->submit(-name=>'Button1', -value=>'Button1') . ' +</td>'; print STDOUT <<EOT; </tr> <tr> <td>I AM ON THE SECOND ROW</td>
    etc, etc.
RE: Formatting CGI
by Anonymous Monk on Apr 07, 2000 at 07:24 UTC
    I know this is the Perl monastery, but for things like GIF alignment and stuff why not use PHP? You *can* interface PHP with CGI and MySQL all together... not to make the Holy Gates of Wisdom and Perl unclean with the mention of another Language, but I think it's good to find a Tao of All Things. (www.php.net)
      The perl monks welcome all, regardless of gender, race, or language. :)