--- David Gilden <[EMAIL PROTECTED]> wrote:
> Hi,
>  
>  I am having bit of a struggle getting the following code to work:
>  
> Here are my two questions, first is there a cleaner way of dealing the 'radio button 
>group' 
> next is the building of a hash of hashs, and  I can not seem to sort desired 
>criteria.
> As a PERL neophyte all help is appreciated,
> Thx,
> Dave 

This should really be in the beginners-cgi list.

brian d foy is correct.  Using CGI.pm's HTML generating functions is much easier if 
you must put
your HTML in the code.  Several reasons:

1.  The HTML that it generates is much more likely to be formatted correctly.
2.  It now produces valid XHTML.
3.  It's almost impossible to mis-nest tags.
4.  It provides a rough "syntax check" of your code which you cannot do with raw 
printing of your
code.
5.  Fields are sticky by default (i.e., send users back to the form and it will fill 
in the form
data for you!)

Here's the bulk of your form reproduced using these functions.  This only took a 
couple of minutes
(it's *really* that easy once you get used to the odd syntax).  I just changed it down 
to the
radio button area.  Take a look at how that is done and I think you'll be pleased with 
it.

#!/usr/bin/perl -w
use strict;
use CGI::Pretty qw/:standard :html :cgi-lib/;
my ($sort_by,$new_row ,$row_count, $first_name, $last_name, $birthday, $gender, 
$height, $weight);

$new_row ="<tr>\n";

require "dbi-lib.pl";

&initialize_dbi;
&run_statement("select * from friends;");

## Get sort order via post method
my %FORM_DATA = Vars;

$sort_by = $FORM_DATA{sort_order} || 0;
####

my %sort_order =(
    0 => 'Nothing',
    1 => 'Hash',
    2 => 'First Name',
    3 => 'Last Name',
    4 => 'Birthday',
    5 => 'Sex',
    6 => 'Height',
    7 => 'Weight',
);


print header,
      start_html( -title => 'Some title' ),
      start_form( -method => 'POST' ),
      p( 'Sort Database by' .
          font( { color => 'red' }, "$sort_order{ $sort_by }:" )
      ),
      radio_group(
        -name    => 'sort_order',
        -values  => [ keys %sort_order ],
        -default => $sort_by,
        -labels  => \%sort_order
      ),
      submit( -value => 'Sort Data' ),
      end_form,
      end_html;

Cheers,
Curtis "Ovid" Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to