in reply to CGI Checkboxes

michellem writes:
When a field is a checkbox, the data is saved to the database in the form of a comma delimited list.

I know that this is not what you are asking for...

If I understand you correctly, you are planning to stuff a list of values into a single column.

This may not be a good idea. The first three normal forms are probably more important to datbase programming than use strict and use warnings are to perl programming.

You are (apparently) violating the First Normal Form. Whole books have been written on the subject and there are many, mnay good reasons to normalize. One of them is that normalized data is a lot easier to deal with. SQL is to Perl, as Perl is to C in terms of the ratio of lines of code to results.

Sorry, for lack of more specific examples. Hope this helps



email: mandog

Replies are listed 'Best First'.
Re: First Normal Form (was Re: CGI Checkboxes)
by michellem (Friar) on Oct 26, 2001 at 20:26 UTC
    mandog writes
    You are (apparently) violating the First Normal Form.

    Well, yes and no. I understand well the idea of normalizing databases, and use it when I design my own databases. But I'm not writing a specific application for a specific database - I'm writing a generic application to allow people to edit their own database data, using schema and form elements that they have designed. On the web, this generally flat file, not relational (although I'm working on getting this to work for relational databases).

    The standard way that checkboxes work is to allow multiple choices within one field. I'm just trying to allow people to work with this standard. If they know something about database atomicity, then they should design their databases accordingly. :-)

      I don't know if a working example would help, but here it is anyway:

      #!/perl/bin/perl -w use strict; use CGI; my $query = new CGI; my @checks_list = qw(eenie meenie minie moe); my @check_array = qw(eenie moe); my %hash = ( eenie => 'Eenie', meenie => 'Meenie', minie => 'Minie', moe => 'Moe'); print $query->header(), $query->start_html(), $query->start_form(), $query->checkbox_group( -name => 'group_name', -values => \@checks_list, -default => \@check_array, -labels => \%hash, -rows => 2, -columns => 2), $query->end_form(), $query->end_html();
        Thanks, but I need to use the param function - these checkboxes are defined by data in a database - I can't pre-define them.

        I hate to brute-force it, and not use CGI, which I can do, but I'd rather use CGI. But it's looking grim...

        Update: Here's the brute force code that works:

        elsif ($type =~ /check/) { my $i=0; print "$english:\n"; (my $values, my $labels) = split (':',$params[0]); my @checks_list = split (';',$values); my @clabels_list = split (';',$labels); foreach(@checks_list) { my $index=index $real_fields{$name},$_; if ($index != -1) { print "$clabels_list[$i]<INPUT TYPE=\"checkbox\" N +AME=\"$name\" VALUE=\"$_\" CHECKED>\n"; } else { print "$clabels_list[$i]<INPUT TYPE=\"checkbox\" N +AME=\"$name\" VALUE=\"$_\">\n"; } $i++; } print $q->br(); }

        I'd love it if someone found a way to use the param function of CGI to get this to work!