Module FormValidator::InputProfile
In: formvalidator.rb

This module contains all the valid methods that can be invoked from an input profile. All keys in an input profile can be specified as strings or symbols.

Methods
constraint_regexp_map    constraints    defaults    dependencies    dependency_groups    field_filter_regexp_map    field_filters    filters    optional    optional_regexp    require_some    required    required_regexp    untaint_all_constraints    untaint_constraint_fields   
Public Instance methods
required()

Takes an array, symbol, or string.

Any fields in this list which are not present in the user input will be reported as missing.

   :required => [:name, :age, :phone]
optional()

Takes an array, symbol, or string.

Any fields in this list which are not If optional fields are present in the form hash, they'll go through any specified constraint checks and filters. Any fields that aren't in the optional or required list are reported as unknown.

    :optional => [:name, :age, :phone]
required_regexp()

Takes a regular expression.

Specifies additional fieds which are required. If a given form element matches the regexp, it must have data, or it will be reported in the missing field list.

    :required_regexp => /name/
optional_regexp()

Takes a regular expression.

Any form fields that match the regexp specified are added to the list of optional fields.

    :required_regexp => /name/
require_some()

Takes a hash with each key pointing to an array.

The first field in the array is the number of fields that must be filled. The field is an array of fields to choose from. If the required number of fields are not found, the key name is reported in the list of missing fields.

    :require_some => { :check_or_cc => [1, %w{cc_num check_no}] }
defaults()

Takes a hash.

Fills in defaults but does not override required fields.

    :defaults => { :country => "USA" }
dependencies()

Takes a hash.

This hash which contains dependencies information. This is for the case where one optional fields has other requirements. The dependencies can be specified with an array. For example, if you enter your credit card number, the field cc_exp and cc_type should also be present. If the dependencies are specified with a hash then the additional constraint is added that the optional field must equal a key on the form for the dependencies to be added.

    :dependencies => { :paytype => { :CC => [ :cc_type, :cc_exp ],
                                     :Check => :check_no
                                   }}

    :dependencies => { :street => [ :city, :state, :zipcode ] }
dependency_groups()

Takes a hash pointing to an array.

If no fields are filled, then fine, but if any fields are filled, then all must be filled.

    :dependency_groups => { :password_group => [ :pass1, :pass2 ] }
filters()

Takes an array, symbol, or string.

Specified filters will be applied to ALL fields.

    :filters => :strip
field_filters()

Takes a hash.

Applies one or more filters to the specified field. See FormValidator::Filters for a list of builtin filters.

    :field_filters => { :home_phone => :phone }
field_filter_regexp_map()

Takes a regexp.

Applies one or more filters to fields matching regexp.

    :field_filter_regexp_map => { /name/ => :capitalize }
untaint_all_constraints()

Takes true.

If this is set, all fields which pass a constraint check are untainted. This is overridden by untaint_constraint_fields.

    :untaint_all_constraints => true
untaint_constraint_fields()

Takes an array.

Any field found in this array will be untainted if it passes a constraint check.

    :untaint_constraint_fields => %w{ name age }
constraint_regexp_map()

Takes a hash.

Applies constraints to fields matching regexp and adds failed fields to the list of invalid fields. If untainting is enabled then the form element will be set to the result of the constraint method.

    :constraint_regexp_map => { /code/ => :zip }
constraints()

Takes a hash.

Apply constraint to each key and add failed fields to the invalid list. If untainting is enabled then the form element will be set to the result of the constraint method. Valid constraints can be one of the following: