Changeset 74 in text-formbuilder for trunk


Ignore:
Timestamp:
03/16/05 16:16:30 (20 years ago)
Author:
peichman
Message:

deprecated the !field directive
updated docs for generated code

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r73 r74  
    88    * using <fieldset> tags instead of <h2> to mark form sections 
    99    * group fields can have comments 
     10    * deprecated the !field directive 
    1011     
    11120.09 - 10 Mar 2005 
  • trunk/lib/Text/FormBuilder.pm

    r73 r74  
    820820CGI script to render the form. This way, you only need CGI::FormBuilder on 
    821821your server, and you don't have to parse the form spec each time you want  
    822 to display your form. The generated module has one function (not exported) 
    823 called C<get_form>, that takes a CGI object as its only argument, and returns 
    824 a CGI::FormBuilder object. 
     822to display your form. The generated module is a subclass of L<CGI::FormBuilder>, 
     823that will passa long any constructor arguments to FormBuilder, and set up 
     824the fields for you. 
    825825 
    826826First, you parse the formspec and write the module, which you can do as a one-liner: 
     
    828828    $ perl -MText::FormBuilder -e"Text::FormBuilder->parse('formspec.txt')->write_module('My::Form')" 
    829829 
    830 B<FIXME> And then, in your CGI script, use the new module: 
     830And then, in your CGI script, use the new module: 
    831831 
    832832    #!/usr/bin/perl -w 
     
    837837     
    838838    my $q = CGI->new; 
    839     my $form = My::Form::get_form($q); 
     839    my $form = My::Form->new; 
    840840     
    841841    # do the standard CGI::FormBuilder stuff 
     
    868868    use warnings; 
    869869     
    870     use CGI; 
    871870    use CGI::FormBuilder; 
    872871     
    873     my $q = CGI->new; 
    874      
    875872    my $form = CGI::FormBuilder->new( 
    876         params => $q, 
    877         # ... lots of other stuff to set up the form ... 
     873        # lots of stuff here... 
    878874    ); 
    879875     
    880     $form->field( name => 'month' ); 
    881     $form->field( name => 'day' ); 
    882      
    883     unless ( $form->submitted && $form->validate ) { 
     876    # ...and your field setup subs are here 
     877    $form->field(name => '...'); 
     878         
     879    unless ($form->submitted && $form->validate) { 
    884880        print $form->render; 
    885881    } else { 
    886         # do something with the entered data ... 
    887         # this is where your form processing code should go 
     882        # do something with the entered data 
    888883    } 
    889884 
     
    935930=head1 LANGUAGE 
    936931 
     932    # name field_size growable label hint type other default option_list validate 
     933     
    937934    field_name[size]|descriptive label[hint]:type=default{option1[display string],...}//validate 
    938935     
     
    986983=item C<!field> 
    987984 
    988 Include a named instance of a group defined with C<!group>. 
     985B<DEPRACATED> Include a named instance of a group defined with C<!group>. 
    989986 
    990987=item C<!title> 
     
    10191016=back 
    10201017 
    1021 =head2 Fields 
     1018=head2 Strings 
    10221019 
    10231020First, a note about multiword strings in the fields. Anywhere where it says 
     
    10421039    unlabeled_field|'' 
    10431040 
    1044 Now, back to the beginning. Form fields are each described on a single line. 
    1045 The simplest field is just a name (which cannot contain any whitespace): 
     1041=head2 Fields 
     1042 
     1043Form fields are each described on a single line. The simplest field is 
     1044just a name (which cannot contain any whitespace): 
    10461045 
    10471046    color 
    10481047 
    10491048This yields a form with one text input field of the default size named `color'. 
    1050 The generated label for this field would be ``Color''. To add a longer or more\ 
     1049The generated label for this field would be ``Color''. To add a longer or more 
    10511050descriptive label, use: 
    10521051 
     
    11001099    person*:text 
    11011100 
     1101To create a C<radio> or C<select> field that includes an "other" option, 
     1102append the string C<+other> to the field type: 
     1103 
     1104    position:select+other 
     1105 
     1106Or, to let FormBuilder decide whether to use radio buttons or a dropdown: 
     1107 
     1108    position+other 
     1109 
     1110Like growable fields, 'other' fields require FormBuilder 3.02 or higher. 
     1111 
    11021112For the input types that can have options (C<select>, C<radio>, and 
    11031113C<checkbox>), here's how you do it: 
     
    12131223=head2 Language/Parser 
    12141224 
     1225Deprecate the C<!field> directive 
     1226 
    12151227Allow renaming of the submit button; allow renaming and inclusion of a  
    12161228reset button 
  • trunk/lib/Text/FormBuilder/grammar

    r73 r74  
    146146 
    147147group_field: '!field' group_name name label(?) 
    148     {  
     148    { 
     149        warn "[Text::FormBuilder] The !field directive has been DEPRECATED (input file line $thisline). Please use the name:GROUP style"; 
    149150        push @lines, [ 'group', { name => $item{name}, label => $item{'label(?)'}[0], group => $item{group_name} } ]; 
    150151    } 
     
    154155field_group: name label(?) hint(?) group_type comment(?) 
    155156    { 
    156         warn "[$thisline] comment = $item{'hint(?)'}[0]\n" if $item{'hint(?)'}[0]; 
     157        #warn "[$thisline] comment = $item{'hint(?)'}[0]\n" if $item{'hint(?)'}[0]; 
    157158        #warn "[$thisline] field $item{name} is $item{group_type}\n"; 
    158159        push @lines, [ 'group', { 
Note: See TracChangeset for help on using the changeset viewer.