Changeset 28 in text-formbuilder for trunk/lib/Text/FormBuilder.pm


Ignore:
Timestamp:
11/17/04 09:07:38 (19 years ago)
Author:
peter
Message:

fixed errors from undefined references
removed old field/heading code from grammar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Text/FormBuilder.pm

    r26 r28  
    66use vars qw($VERSION); 
    77 
    8 $VERSION = '0.06_01'; 
     8$VERSION = '0.06_02'; 
    99 
    1010use Carp; 
     
    1212use CGI::FormBuilder; 
    1313 
    14 # the default options passed to CGI::FormBuilder->new 
     14# the static default options passed to CGI::FormBuilder->new 
    1515my %DEFAULT_OPTIONS = ( 
    1616    method => 'GET', 
     
    7777     
    7878    # substitute in custom pattern definitions for field validation 
    79     if (my %patterns = %{ $self->{form_spec}{patterns} }) { 
     79    if (my %patterns = %{ $self->{form_spec}{patterns} || {} }) { 
    8080        foreach (@{ $self->{form_spec}{fields} }) { 
    8181            if ($$_{validate} and exists $patterns{$$_{validate}}) { 
     
    8585    } 
    8686     
    87 ##     # so we don't get all fields required 
    88 ##     foreach (@{ $self->{form_spec}{fields} }) { 
    89 ##         delete $$_{validate} unless $$_{validate}; 
    90 ##     } 
    91  
    9287    # expand groups 
    93     my %groups = %{ $self->{form_spec}{groups} }; 
    94     foreach (grep { $$_[0] eq 'group' } @{ $self->{form_spec}{lines} }) { 
     88    my %groups = %{ $self->{form_spec}{groups} || {} }; 
     89    foreach (grep { $$_[0] eq 'group' } @{ $self->{form_spec}{lines} || [] }) { 
    9590        $$_[1]{group} =~ s/^\%//;       # strip leading % from group var name 
    9691         
     
    107102     
    108103    $self->{form_spec}{fields} = []; 
    109     for my $line (@{ $self->{form_spec}{lines} }) { 
     104    for my $line (@{ $self->{form_spec}{lines} || [] }) { 
    110105        if ($$line[0] eq 'group') { 
    111106            push @{ $self->{form_spec}{fields} }, $_ foreach @{ $$line[1]{group} }; 
     
    117112     
    118113    # substitute in list names 
    119     my %lists = %{ $self->{form_spec}{lists} }; 
     114    my %lists = %{ $self->{form_spec}{lists} || {} }; 
    120115    foreach (@{ $self->{form_spec}{fields} }) { 
    121116        next unless $$_{list}; 
     
    169164            data => { 
    170165                lines       => $self->{form_spec}{lines}, 
    171                 headings    => $self->{form_spec}{headings}, 
    172166                author      => $self->{form_spec}{author}, 
    173167                description => $self->{form_spec}{description}, 
     
    215209    # don't dump $VARn names 
    216210    $Data::Dumper::Terse = 1; 
    217      
    218     my $title       = $self->{form_spec}{title} || ''; 
    219     my $author      = $self->{form_spec}{author} || ''; 
    220     my $description = $self->{form_spec}{description} || ''; 
    221      
    222     my $headings    = Data::Dumper->Dump([$self->{form_spec}{headings}],['headings']); 
    223     my $lines       = Data::Dumper->Dump([$self->{form_spec}{lines}],['lines']); 
    224     my $fields      = Data::Dumper->Dump([ [ map { $$_{name} } @{ $self->{form_spec}{fields} } ] ],['fields']); 
    225211     
    226212    my %options = ( 
     
    238224            data => { 
    239225                lines       => $self->{form_spec}{lines}, 
    240                 headings    => $self->{form_spec}{headings}, 
    241226                author      => $self->{form_spec}{author}, 
    242227                description => $self->{form_spec}{description}, 
     
    338323        $OUT .= (grep { $$_{invalid} } @group_fields) ? qq[  <tr class="invalid">\n] : qq[  <tr>\n]; 
    339324         
    340         #TODO: validated but not required fields 
    341         # in a form spec: //EMAIL? 
    342          
    343325        $OUT .= '    <th class="label">'; 
    344326        $OUT .= (grep { $$_{required} } @group_fields) ? qq[<strong class="required">$$line[1]{label}:</strong>] : "$$line[1]{label}:"; 
     
    740722=head1 TODO 
    741723 
    742 DWIM for single valued checkboxes (e.g. C<moreinfo|Send me more info:checkbox>) 
    743  
    744724Use the custom message file format for messages in the built in template 
    745725 
    746726C<!section> directive to split up the table into multiple tables, each 
    747727with their own id and (optional) heading 
     728 
     729Use HTML::Template instead of Text::Template for the built in template 
     730(since CGI::FormBuilder users may be more likely to already have HTML::Template) 
    748731 
    749732Better examples in the docs (maybe a standalone or two as well) 
Note: See TracChangeset for help on using the changeset viewer.