fivalidator.class.php

FormIt

Copyright 2009-2011 by Shaun McCormick shaun@modx.com

FormIt is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

FormIt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with FormIt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package
formit

\fiValidator

Handles custom validation on fields. Allows for specific, defined validators by FormIt, or custom Validators that are MODX Snippets.

Validation can be chained to do proper order-of-execution for field value checking.

package
formit

Properties

Propertypublicarray  $errors= 'array'

Default valuearrayDetails
Type
array
access
public
Propertypublicarray  $errorsRaw= 'array'

Default valuearrayDetails
Type
array
access
public
Propertypublicarray  $fields= 'array'

Default valuearrayDetails
Type
array
access
public
Propertypublic\FormIt  $formit= 'null'

Default valuenullDetails
Type
\FormIt
access
public
Propertypublic\modX  $modx= 'null'

Default valuenullDetails
Type
\modX
access
public

Methods

methodpublic  __construct( \FormIt $formit, array $config = array ) : \fiValidator
The constructor for the fiValidator class
Parameters
Name Type Description
$formit \FormIt

&$formit A reference to the FormIt class instance.

$config array Optional. An array of configuration parameters.
Returns
Type Description
\fiValidator
methodprotected  _getErrorMessage( string $field, string $parameter, string $lexiconKey, array $properties = array ) : null|string
Check for a custom error message, otherwise use a lexicon entry.
Parameters
Name Type Description
$field string
$parameter string
$lexiconKey string
$properties array
Returns
Type Description
nullstring
methodprivate  _validate( string $k, string $v, array $fieldValidators = array ) : void
Helper method for validating fields
Parameters
Name Type Description
$k string
$v string
$fieldValidators array
methodpublic  addError( string $key, string $value ) : string
Adds an error to the stack.
Parameters
Name Type Description
$key string The field to add the error to.
$value string The error message.
Returns
Type Description
string
Details
access
private
methodpublic  allowTags( string $key, string $value, string $allowedTags ) : boolean
Strip all tags in the field. The parameter can be a string of allowed tags.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$allowedTags string

A comma-separated list of tags to allow in the field's value. Leave blank to allow all.

Returns
Type Description
boolean
methodpublic  blank( string $key, string $value ) : boolean
Checks to see if field is blank.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
Returns
Type Description
boolean
methodpublic  contains( string $key, string $value, string $expr ) : boolean
See if field contains a certain value.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$expr string The regular expression to check against the field
Returns
Type Description
boolean
methodpublic  email( string $key, string $value ) : boolean
Checks to see if field value is an actual email address.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
Returns
Type Description
boolean
methodpublic  getErrors( ) : array
Get all errors in the stack
Returns
Type Description
array
methodpublic  getRawErrors( ) : array
Get all raw errors in the stack (errors without the wrapper)
Returns
Type Description
array
methodpublic  hasErrors( ) : boolean
Check to see if there are any validator errors in the stack
Returns
Type Description
boolean
methodpublic  isDate( string $key, string $value, string $format = %m/%d/%Y ) : boolean
Checks to see if the field is a valid date. Allows for date formatting as well.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$format string The format of the date
Returns
Type Description
boolean
methodpublic  isNumber( string $key, string $value ) : boolean
Checks to see if the field is a number.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
Returns
Type Description
boolean
methodpublic  islowercase( string $key, string $value ) : boolean
Checks to see if a string is all lowercase
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
Returns
Type Description
boolean
methodpublic  isuppercase( string $key, string $value ) : boolean
Checks to see if a string is all uppercase
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
Returns
Type Description
boolean
methodpublic  maxLength( string $key, string $value, int $param = 999 ) : boolean
Checks to see if field value is longer than $param.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$param int The maximum length the field can be
Returns
Type Description
boolean
methodpublic  maxValue( string $key, string $value, int $param = 0 ) : boolean
Checks to see if field value is greater than $param.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$param int The maximum value the field can be
Returns
Type Description
boolean
methodpublic  minLength( string $key, string $value, int $param = 0 ) : boolean
Checks to see if field value is shorter than $param.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$param int The minimum length the field can be
Returns
Type Description
boolean
methodpublic  minValue( string $key, string $value, int $param = 0 ) : boolean
Checks to see if field value is less than $param.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$param int The minimum value the field can be
Returns
Type Description
boolean
methodpublic  password_confirm( string $key, string $value, string $param = password_confirm ) : boolean
Checks to see if passwords match.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$param string The parameter passed into the validator that contains the field to check the password against
Returns
Type Description
boolean
methodpublic  processErrors( ) : void
Process the errors that have occurred and setup the appropriate placeholders
methodpublic  range( string $key, string $value, string $ranges = 0-1 ) : boolean
Validates value between a range, specified by min-max.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$ranges string The range the value should reside in
Returns
Type Description
boolean
methodpublic  regexp( string $key, string $value, string $expression ) : boolean
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$expression string The regexp to use
Returns
Type Description
boolean
methodpublic  required( string $key, string $value ) : boolean
Checks to see if field is required.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
Returns
Type Description
boolean
methodpublic  reset( ) : void
Resets the validator
methodpublic  strip( string $key, string $value, string $param ) : boolean
Strip a string from the value.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$param string The value to strip from the field
Returns
Type Description
boolean
methodpublic  stripTags( string $key, string $value, string $allowedTags ) : boolean
Strip all tags in the field. The parameter can be a string of allowed tags.
Parameters
Name Type Description
$key string The name of the field
$value string The value of the field
$allowedTags string

A comma-separated list of tags to allow in the field's value

Returns
Type Description
boolean
methodpublic  validate( string $key, mixed $value, string $type ) : boolean
Validates a field based on a custom rule, if specified
Parameters
Name Type Description
$key string The key of the field
$value mixed The value of the field
$type string Optional. The type of the validator to apply. Can either be a method name of fiValidator or a Snippet name.
Returns
Type Description
boolean
Details
access
public
methodpublic  validateFields( \fiDictionary $dictionary, string $validationFields ) : array
Validates an array of fields. Returns the field names and values, with the field names stripped of their validators.

The key names can be in this format:

name:validator=param:anotherValidator:oneMoreValidator=param

Parameters
Name Type Description
$dictionary \fiDictionary
$validationFields string
Returns
Type Description
array
Details
access
public
Documentation was generated by DocBlox 0.13-DEV.