CGI-QuickForm
    
    
  
  
  
view release on metacpan or search on metacpan
QuickForm.pm view on Meta::CPAN
@EXPORT_OK = qw( colour color ) ;
*color = \&colour ;
sub colour { qq{<span style="color:$_[0]">$_[1]</span>} }
sub show_form {
    my %form = (
        -LANGUAGE         => 'en',         # Language to use for default messages
        -USER_REQUIRED    => undef,
        -USER_INVALID     => undef,
        -REQUIRED_HTML    => '<span style="font-weight:bold;color:BLUE">+</span>',
        -INVALID_HTML     => '<span style="font-weight:bold;color:RED">*</span>',
        -TITLE            => 'Quick Form', # Default page title and heading
        -INTRO            => undef,
        -HEADER           => undef,      
        -FOOTER           => undef,
        -NAME             => '',
        -JSCRIPT          => {},
        -ONSUBMIT         => '',
        -ACCEPT           => \&_on_valid_form,
        -VALIDATE         => undef,        # Call this to validate entire form
        -SIZE             => undef,
QuickForm.pm view on Meta::CPAN
    show_form(
        -ACCEPT           => \&on_valid_form, 
        -BORDER           => 0,
        -FOOTER           => undef,
        -HEADER           => undef,      
        -INTRO            => undef,
        -LANGUAGE         => 'en',
        -USER_REQUIRED    => undef,
        -USER_INVALID     => undef,
        -TITLE            => 'Test Form',
        -REQUIRED_HTML    => '<span style="font-weight:bold;color:BLUE">+</span>',
        -INVALID_HTML     => '<span style="font-weight:bold;color:RED">*</span>',
        -VALIDATE         => undef,       # Set this to validate the entire record
        -SIZE             => undef,
        -MAXLENGTH        => undef,
        -ROWS             => undef,
        -COLUMNS          => undef,
        -CHECK            => 1,
        -SPACE            => 0, # Output some newlines to assist debugging if 1
        -MULTI_COLUMN     => 0,
        -NAME             => undef,
        -ONSUBMIT         => undef,
QuickForm.pm view on Meta::CPAN
Optional string. If you specify C<-TITLE> you may want to specify this field
too; it puts a paragraph of text before the form. The English default is
"Please enter the information.", there is a default for each supported
language (see C<-LANGUAGE>).
=item C<-INVALID_HTML> 
Optional HTML string. Default is:
    <span style="font-weight:bold;color:RED">*</span>
You can over-ride this to set your own marker to indicate an invalid field.
You could use an image tag for example:
    <img src="/images/invalid.jpg" alt="*" />
Note that if you use your own C<-USER_REQUIRED> or C<-USER_INVALID> strings,
this string will replace the sequence C<~I~> if it occurs.
See C<example1> and the companion option C<-REQUIRED_HTML>.
QuickForm.pm view on Meta::CPAN
=item C<-ONSUBMIT>
Optional string. If specified this string is given to the start_form()
function as its C<-onSubmit> option; used with Javascript.
(See C<-JSCRIPT> and C<-NAME>.)
=item C<-REQUIRED_HTML> 
Optional HTML string. Default is:
    <span style="font-weight:bold;color:BLUE">+</span>
You can over-ride this to set your own marker to indicate a required field.
Note that if you use your own C<-USER_REQUIRED> or C<-USER_INVALID> strings,
this string will replace the sequence C<~R~> if it occurs.
See C<example1> and the companion option C<-INVALID_HTML>.
=item C<-TITLE> 
QuickForm.pm view on Meta::CPAN
preceeds C<-HEADLINE> should normally set C<-END_ROW> to true; this isn't done
automatically in case your form has two or more columns and you want to have
different headlines above each column. Thus a typical headline field looks
like:
    {
        -LABEL           => 'General Information',
        -HEADLINE        => 1,
        -COLSPAN         => 2, # Probably needs to be more for -MULTI_COLUMN
        -END_ROW         => 1,
        -STYLE_FIELDNAME => 'style="background-color:black;color:white;font-weight:bold"', 
    },
=item C<-LABEL> 
Required string. This is the display label for the field. It is also used as
the field's name if no C<-name> option is used.
=item C<-REQUIRED> 
    show_form(
        -ACCEPT           => \&on_valid_form, 
        -BORDER           => 0,
        -FOOTER           => undef,
        -HEADER           => undef,      
        -INTRO            => undef,
        -LANGUAGE         => 'en',
        -USER_REQUIRED    => undef,
        -USER_INVALID     => undef,
        -TITLE            => 'Test Form',
        -REQUIRED_HTML    => '<span style="font-weight:bold;color:BLUE">+</span>',
        -INVALID_HTML     => '<span style="font-weight:bold;color:RED">*</span>',
        -VALIDATE         => undef,       # Set this to validate the entire record
        -SIZE             => undef,
        -MAXLENGTH        => undef,
        -ROWS             => undef,
        -COLUMNS          => undef,
        -CHECK            => 1,
        -SPACE            => 0, # Output some newlines to assist debugging if 1
        -MULTI_COLUMN     => 0,
        -NAME             => undef,
        -ONSUBMIT         => undef,
Optional string. If you specify C<-TITLE> you may want to specify this field
too; it puts a paragraph of text before the form. The English default is
"Please enter the information.", there is a default for each supported
language (see C<-LANGUAGE>).
=item C<-INVALID_HTML> 
Optional HTML string. Default is:
    <span style="font-weight:bold;color:RED">*</span>
You can over-ride this to set your own marker to indicate an invalid field.
You could use an image tag for example:
    <img src="/images/invalid.jpg" alt="*" />
Note that if you use your own C<-USER_REQUIRED> or C<-USER_INVALID> strings,
this string will replace the sequence C<~I~> if it occurs.
See C<example1> and the companion option C<-REQUIRED_HTML>.
=item C<-ONSUBMIT>
Optional string. If specified this string is given to the start_form()
function as its C<-onSubmit> option; used with Javascript.
(See C<-JSCRIPT> and C<-NAME>.)
=item C<-REQUIRED_HTML> 
Optional HTML string. Default is:
    <span style="font-weight:bold;color:BLUE">+</span>
You can over-ride this to set your own marker to indicate a required field.
Note that if you use your own C<-USER_REQUIRED> or C<-USER_INVALID> strings,
this string will replace the sequence C<~R~> if it occurs.
See C<example1> and the companion option C<-INVALID_HTML>.
=item C<-TITLE> 
preceeds C<-HEADLINE> should normally set C<-END_ROW> to true; this isn't done
automatically in case your form has two or more columns and you want to have
different headlines above each column. Thus a typical headline field looks
like:
    {
        -LABEL           => 'General Information',
        -HEADLINE        => 1,
        -COLSPAN         => 2, # Probably needs to be more for -MULTI_COLUMN
        -END_ROW         => 1,
        -STYLE_FIELDNAME => 'style="background-color:black;color:white;font-weight:bold"', 
    },
=item C<-LABEL> 
Required string. This is the display label for the field. It is also used as
the field's name if no C<-name> option is used.
=item C<-REQUIRED> 
eg/example2 view on Meta::CPAN
# May be used/distributed under the GPL.
# WARNING - this program is provided as an example of QuickForm use and not as
# an example of production quality CGI code - it may not be secure. 
use strict ;
use CGI qw( :standard :html3 ) ;
use CGI::QuickForm qw( show_form colour ) ;
my $STYLE_HEADLINE   = 'style="background-color:black;color:white;font-weight:bold"' ;
show_form(
    -MULTI_COLUMN     => 1, # MULTI_COLUMN
    -TITLE            => 'Test Form',
    -ACCEPT           => \&on_valid_form, 
    -SIZE             => 25,
    -SPACE            => 1,
    -CHECK            => ( query_string() =~ /QFCHK=0/o ? 0 : 1 ), 
    -FOOTER           => qq{<a href="} . 
                         url() . #"
eg/example4 view on Meta::CPAN
# LIKE. The CSV driver does not appear to support WHERE at all.
#   my $TABLE    = 'contacts_csv' ;
#   my $CONNECT  = "DBI:CSV:f_dir=$DATABASE" ;
my $TABLE           = 'contacts' ; 
my $CONNECT         = "DBI:XBase:/root/web/db/contactsqf" ; 
my @FIELD    = (
            {
                -DB_NAME   => 'ID',
                -DB_QUOTE  => 1,       # 0 for numeric fields
                -DB_HTML   => 'tt',    # e.g. bold, italic, h1, tt, etc.
                -DB_ALIGN  => 'RIGHT', # LEFT (default), CENTER, RIGHT
                -DB_VALIGN => undef,   # BOTTOM, CENTER, TOP 
                -DB_PREFIX => undef,   # e.g. £ or $ etc.
                -LABEL     => 'ID',
                -END_ROW   => 1,
                -REQUIRED  => 1,
                -maxlen    => 12,
            },
            {
                -DB_NAME   => 'FORENAME',
eg/example4 view on Meta::CPAN
    my( $field, $html ) = @_ ;
    if( $html eq 'mailto' or $html eq 'email' ) {
        $field = qq{<a href="mailto:$field">$field</a>} ;
    }
    elsif( $html eq 'url' or $html eq 'web' ) {
        my $protocol = $field =~ m,^(?:http|ftp|gopher|wais|/), ? 
                            '' : 'http://' ;
        $field = qq{<a href="$protocol$field">$field</a>} ;
    }
    elsif( $html eq 'b' or $html eq 'bold' ) {
        $field = qq{<b>$field</b>} ;
    }
    elsif( $html eq 'i' or $html eq 'italic' ) {
        $field = qq{<i>$field</i>} ;
    }
    elsif( $html eq 'bi' or $html eq 'bolditalic' ) {
        $field = qq{<b><i>$field</i></b>} ;
    }
    elsif( $html eq 'tt' or $html eq 'fixed' ) {
        $field = qq{<tt>$field</tt>} ;
    }
    elsif( $html =~ /^h([1-6])$/o ) {
        $field = qq{<h$1>$field</h$1>} ;
    }
    $field ;
eg/example6 view on Meta::CPAN
# http://perl.apache.org
use strict ;
require 'CGI/Apache.pm' ;   # ADDED FOR MOD_PERL
use Apache::Constants qw( :common ) ;   # ADDED FOR MOD_PERL
use CGI qw( :standard :html3 ) ;
use CGI::QuickForm qw( show_form colour ) ;
my $STYLE_FIELDVALUE = 'style="background-color:#DDDDDD"' ;
my $STYLE_HEADLINE   = 'style="background-color:black;color:white;font-weight:bold"' ;
sub handler { # ADDED FOR MOD_PERL
    show_form(
        -MULTI_COLUMN     => 1, # MULTI_COLUMN
        -SPACE            => 0,
        -CHECK            => ( query_string() =~ /QFCHK=0/o ? 0 : 1 ), 
        -FOOTER           => qq{<a href="} . #" 
                             url() . path_info() .  # ADDED FOR MOD_PERL
                             qq{?QFCHK=0\&Age=28\&Surname=Bloggs\&Forename=Freda">} .#"
( run in 1.151 second using v1.01-cache-2.11-cpan-5dc5da66d9d )