Table of Contents
FormValidator
Layer: Core · Source: lib/core/FormValidator.php:18 (lines 18–254)
class FormValidator
Docblock Metadata
| Tag | Value |
|---|---|
@category | Core Class |
@author | SchizoDuckie |
@version | 1.0 |
@see | https://stackoverflow.com/questions/737385/easiest-form-validation-library-for-php#738510 |
Inheritance
No parent, interface or trait. This is a root type.
Constants (0)
None.
Properties (8)
| Visibility | Type | Name | Default | Line |
|---|---|---|---|---|
public static | static | $regexes | array( 'date' ⇒ “^[0-9]{4}[-/][0-9]{1,2}[-/][0-9]{1,2}\$”,… | 20 |
private | (untyped) | $validations | 37 | |
private | (untyped) | $sanitations | 39 | |
private | (untyped) | $mandatories | 41 | |
private | (untyped) | $equal | 43 | |
private | (untyped) | $errors | 45 | |
private | (untyped) | $corrects | 47 | |
protected | (untyped) | $fields | 49 |
Methods (7)
| Visibility | Method | Summary | Line |
|---|---|---|---|
| public | __construct() | (undocumented) | 51 |
| public | validate() | Validates an array of items (if needed) and returns true or false | 68 |
| public | getJSON() | (undocumented) | 126 |
| public | sanitize() | Sanatizes an array of items according to the $this→sanitations | 159 |
| private | addError() | Adds an error to the errors array. | 177 |
| private static | sanitizeItem() | Sanatize a single var according to $type. | 187 |
| public static | validateItem() | Validates a single var according to $type. | 223 |
__construct()
public function __construct($validations = array(), $mandatories = array(), $sanitations = array(), $equal = array())
lines 51–59 (9)
| Parameter | Type | Default | Description |
|---|---|---|---|
$validations | (untyped) | array() | none |
$mandatories | (untyped) | array() | none |
$sanitations | (untyped) | array() | none |
$equal | (untyped) | array() | none |
validate()
public function validate($items)
lines 68–121 (54)
Validates an array of items (if needed) and returns true or false
JP modofied this function so that it checks fields even if they are not submitted. for example the original code did not check for a mandatory field if it was not submitted. Also the types of non mandatory fields were not checked.
| Parameter | Type | Default | Description |
|---|---|---|---|
$items | (untyped) | required | none |
Returns: (none declared)
getJSON()
public function getJSON()
lines 126–148 (23)
Takes no parameters.
Returns: (none declared)
sanitize()
public function sanitize($items)
lines 159–171 (13)
Sanatizes an array of items according to the $this→sanitations
sanitations will be standard of type string, but can also be specified. For ease of use, this syntax is accepted: $sanitations = array('fieldname', 'otherfieldname'⇒'float');
| Parameter | Type | Default | Description |
|---|---|---|---|
$items | (untyped) | required | none |
Returns: (none declared)
addError()
private function addError($field, $type = 'string')
lines 177–180 (4)
Adds an error to the errors array.
| Parameter | Type | Default | Description |
|---|---|---|---|
$field | (untyped) | required | none |
$type | (untyped) | 'string' | none |
Returns: (none declared)
sanitizeItem()
private static function sanitizeItem($var, $type)
lines 187–215 (29)
Sanatize a single var according to $type.
Allows for static calling to allow simple sanatization
| Parameter | Type | Default | Description |
|---|---|---|---|
$var | (untyped) | required | none |
$type | (untyped) | required | none |
Returns: (none declared)
validateItem()
public static function validateItem($var, $type)
lines 223–253 (31)
Validates a single var according to $type.
Allows for static calling to allow simple validation.
| Parameter | Type | Default | Description |
|---|---|---|---|
$var | (untyped) | required | none |
$type | (untyped) | required | none |
Returns: (none declared)
This page is generated from source by 'tools/gendoc'. Edits will be overwritten.
