class Validation (View source)

Helper functions to use with validating submitting forms.

\@package Helpers

Constants

VALID_NOT_EMPTY

VALID_EMAIL

VALID_INTEGER

VALID_INTEGER_REQUIRED

VALID_UPLOADED_IMAGE

VALID_UPLOADED_IMAGE_REQUIRED

VALID_UPLOADED_FILE

VALID_UPLOADED_FILE_REQUIRED

VALID_TOKEN

VALID_FIELD_INVALID

Properties

protected $fields
protected $fieldsInvalid
protected $data
protected $files
protected $error

Methods

__construct()

No description

addUploadedImage(string $field, string $errorMsg = null, bool $emptyIsOk = true)

Adds a test to a field to ensure that, if set, it is a valid uploaded image.

addRequired(string $field, string $errorMsg = null, string $validate = self::VALID_NOT_EMPTY)

Adds a required field to the form helper object. This will then be typically used in conjunction with the test() method to see if the test is passed.

addUploadedFile(string $field, string $errorMsg = null, bool $emptyIsOk = true)

Adds a test to a field to ensure that, if set, it is a valid uploaded file.

addInteger(string $field, string $errorMsg = null, bool $emptyIsOk = true)

Adds a required field and tests that it is integer only.

addRequiredToken($value, $errorMsg = null)

No description

addRequiredEmail(string $field, string $errorMsg = null)

Adds a required email address to the suite of tests to be run.

setFiles()

Sets the data files array.

setData(array $data)

An associative array that we setup to validate against. Typical usage is $val->setData($_POST);.

invalidate($message)

No description

int
test()

After the validation error helper has been setup, the test() method ensures that all fields that require validation pass. Returns the number of invalid fields (0 = success).

setErrorsFromInvalidFields()

No description

getError()

No description

Details

__construct()

addUploadedImage(string $field, string $errorMsg = null, bool $emptyIsOk = true)

Adds a test to a field to ensure that, if set, it is a valid uploaded image.

Parameters

string $field
string $errorMsg
bool $emptyIsOk Tells whether this can be submitted as empty (e.g. the validation tests only run if someone is actually submitted in the post.)

addRequired(string $field, string $errorMsg = null, string $validate = self::VALID_NOT_EMPTY)

Adds a required field to the form helper object. This will then be typically used in conjunction with the test() method to see if the test is passed.

Parameters

string $field
string $errorMsg
string $validate test to validate against

addUploadedFile(string $field, string $errorMsg = null, bool $emptyIsOk = true)

Adds a test to a field to ensure that, if set, it is a valid uploaded file.

Parameters

string $field
string $errorMsg
bool $emptyIsOk Tells whether this can be submitted as empty (e.g. the validation tests only run if someone is actually submitted in the post.)

addInteger(string $field, string $errorMsg = null, bool $emptyIsOk = true)

Adds a required field and tests that it is integer only.

Parameters

string $field
string $errorMsg
bool $emptyIsOk Tells whether this can be submitted as empty (e.g. the validation tests only run if someone is actually submitted in the post.)

addRequiredToken($value, $errorMsg = null)

Parameters

$value
$errorMsg

addRequiredEmail(string $field, string $errorMsg = null)

Adds a required email address to the suite of tests to be run.

Parameters

string $field
string $errorMsg

setFiles()

Sets the data files array.

setData(array $data)

An associative array that we setup to validate against. Typical usage is $val->setData($_POST);.

Parameters

array $data

invalidate($message)

Parameters

$message

int test()

After the validation error helper has been setup, the test() method ensures that all fields that require validation pass. Returns the number of invalid fields (0 = success).

Return Value

int

protected setErrorsFromInvalidFields()

getError()