- Timestamp:
- 11/17/04 09:07:38 (20 years ago)
- Location:
- trunk/lib/Text
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Text/FormBuilder.pm
r26 r28 6 6 use vars qw($VERSION); 7 7 8 $VERSION = '0.06_0 1';8 $VERSION = '0.06_02'; 9 9 10 10 use Carp; … … 12 12 use CGI::FormBuilder; 13 13 14 # the default options passed to CGI::FormBuilder->new14 # the static default options passed to CGI::FormBuilder->new 15 15 my %DEFAULT_OPTIONS = ( 16 16 method => 'GET', … … 77 77 78 78 # substitute in custom pattern definitions for field validation 79 if (my %patterns = %{ $self->{form_spec}{patterns} }) {79 if (my %patterns = %{ $self->{form_spec}{patterns} || {} }) { 80 80 foreach (@{ $self->{form_spec}{fields} }) { 81 81 if ($$_{validate} and exists $patterns{$$_{validate}}) { … … 85 85 } 86 86 87 ## # so we don't get all fields required88 ## foreach (@{ $self->{form_spec}{fields} }) {89 ## delete $$_{validate} unless $$_{validate};90 ## }91 92 87 # 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} || [] }) { 95 90 $$_[1]{group} =~ s/^\%//; # strip leading % from group var name 96 91 … … 107 102 108 103 $self->{form_spec}{fields} = []; 109 for my $line (@{ $self->{form_spec}{lines} }) {104 for my $line (@{ $self->{form_spec}{lines} || [] }) { 110 105 if ($$line[0] eq 'group') { 111 106 push @{ $self->{form_spec}{fields} }, $_ foreach @{ $$line[1]{group} }; … … 117 112 118 113 # substitute in list names 119 my %lists = %{ $self->{form_spec}{lists} };114 my %lists = %{ $self->{form_spec}{lists} || {} }; 120 115 foreach (@{ $self->{form_spec}{fields} }) { 121 116 next unless $$_{list}; … … 169 164 data => { 170 165 lines => $self->{form_spec}{lines}, 171 headings => $self->{form_spec}{headings},172 166 author => $self->{form_spec}{author}, 173 167 description => $self->{form_spec}{description}, … … 215 209 # don't dump $VARn names 216 210 $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']);225 211 226 212 my %options = ( … … 238 224 data => { 239 225 lines => $self->{form_spec}{lines}, 240 headings => $self->{form_spec}{headings},241 226 author => $self->{form_spec}{author}, 242 227 description => $self->{form_spec}{description}, … … 338 323 $OUT .= (grep { $$_{invalid} } @group_fields) ? qq[ <tr class="invalid">\n] : qq[ <tr>\n]; 339 324 340 #TODO: validated but not required fields341 # in a form spec: //EMAIL?342 343 325 $OUT .= ' <th class="label">'; 344 326 $OUT .= (grep { $$_{required} } @group_fields) ? qq[<strong class="required">$$line[1]{label}:</strong>] : "$$line[1]{label}:"; … … 740 722 =head1 TODO 741 723 742 DWIM for single valued checkboxes (e.g. C<moreinfo|Send me more info:checkbox>)743 744 724 Use the custom message file format for messages in the built in template 745 725 746 726 C<!section> directive to split up the table into multiple tables, each 747 727 with their own id and (optional) heading 728 729 Use 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) 748 731 749 732 Better examples in the docs (maybe a standalone or two as well) -
trunk/lib/Text/FormBuilder/grammar
r25 r28 8 8 %lists, 9 9 %patterns, 10 @fields,11 10 @group, # current group 12 11 %groups, # stored groups of fields 13 @headings,14 12 $type, 15 13 @options, … … 23 21 } 24 22 25 form_spec: (list_def | description_def | group_def | line)(s) 23 form_spec: (list_def | description_def | group_def | line)(s) 26 24 { 27 25 $return = { … … 29 27 author => $author, 30 28 description => $description, 31 lists => \%lists || {}, 32 patterns => \%patterns || {}, 33 headings => \@headings || [], 34 fields => \@fields || [], 35 lines => \@lines || [], 36 groups => \%groups || {}, 29 lists => \%lists, 30 patterns => \%patterns, 31 lines => \@lines, 32 groups => \%groups, 37 33 } 38 34 } … … 71 67 72 68 title: '!title' /.*/ 73 { warn "[Text::Formbuilder] Title redefined at input text line $thisline\n" if defined $title; 74 $title = $item[2] } 69 { 70 warn "[Text::Formbuilder] Title redefined at input text line $thisline\n" if defined $title; 71 $title = $item[2]; 72 } 75 73 76 74 author: '!author' /.*/ 77 { $author = $item[2] } 75 { 76 warn "[Text::Formbuilder] Author redefined at input text line $thisline\n" if defined $author; 77 $author = $item[2]; 78 } 78 79 79 80 pattern_def: '!pattern' var_name pattern … … 82 83 pattern: /.*/ 83 84 84 heading: '!head' /.*/ 85 { 86 warn "[Text::FormBuilder] Header before field " . scalar(@fields) . " redefined at input text line $thisline\n" if defined $headings[@fields]; 87 $headings[@fields] = $item[2]; 88 push @lines, [ 'head', $item[2] ]; 89 } 85 heading: '!head' /.*/ { push @lines, [ 'head', $item[2] ] } 90 86 91 87 group_field: '!field' group_name name label(?) 92 { #warn "[$thisline] $item{group_name}\n";93 88 { 89 push @lines, [ 'group', { name => $item{name}, label => $item{'label(?)'}[0], group => $item{group_name} } ]; 94 90 } 95 91 … … 115 111 $$field{size} = $size if defined $size; 116 112 117 #warn "[$thisline] field $item{name}; context $context\n"; 113 #warn "[$thisline] field $item{name}; context $context\n"; 118 114 if ($context eq 'group') { 119 115 push @group, $field; 120 116 } else { 121 push @fields, $field;122 117 push @lines, [ 'field', $field ]; 123 118 } 124 125 #warn "field $item{name} is required" if $required;126 119 127 120 $type = undef;
Note: See TracChangeset
for help on using the changeset viewer.