Packageindex Classtrees Modulegroups Elementlist Report XML Files

pxdb.content.input

pxdb_validator

pxdb_data
   |
  +-- pxdb_confront
     |
    +-- pxdb_validator

private class pxdb_validator extends pxdb_confront

Form validation in this case means both the post-processing of data -- e.g. adding the http:// to the beginning of a URL if it was ommitted -- and the checking of the post-processed data against the requirements established in the database -- or in any custom functions you define. On the code level, there is a parallel between methods for processing and for validating data. There is also a parallel for the ways that this class can be customized. Validation happens *before* any records are written to the database. This means that if you want to make sure that the 'name' column is unique before allowing a record to be written, you may write a validation function that does a lookup on records and then returns an error or false (i.e. the data passed the validation test). Important: although this class is instantiated by pxdb_input, it is only instantiated to retrieve the errors from the global namespace. Therefore it is not important to register validation functions or set other validator properties to the validation class instantiated by (or bound to) pxdb_input. The real validation is performed by the save() method of pxdb_record class.

AuthorsHans Lellelid <hans@velum.net>
Version$Revision: 1.6 $

 

Methods inherited from pxdb_confront

pxdb_confront, _get_form_element_name, _invoke_user_method, import, _import_uploaded_files, bind_validator

Methods inherited from pxdb_data

pxdb_data, set_show_unapproved, get_datatype, get_datatype_list, get_datatype_array, set_datatype, bind_tpl, bind_auth, lookup_colname, lookup_tfid, get_column_identifiers, get_identifiers, set_user_minimal_columns, sql_minimal_columns, sql_aliased_columns

Public Method Summary

void pxdb_validator()
Initialize vars and load the validator variables if present.
object pxdb_validator &singleton()
Attempts to return a reference to an already-instantiated validator class.
void set_validators_path(string $path)
Set path to use for including validator scripts.
void register_type_validator(string $type, mixed $function)
Register a function for validating a particular type of input.
boolean register_field_validator(string $field, mixed $function, [ mixed $datatype ])
Register a function for validating a particular field.
void register_type_processor(string $type, mixed $function)
Register a function for post-processing a particular type of input.
boolean register_field_processor(string $field, mixed $function, [ mixed $datatype ])
Register a function for post-processing a particular field.
mixed process(int $tfid, string $fname, mixed $value)
Performs post-process function on data for a particular typesfield.
mixed validate(integer $tfid, string $fname, mixed $value)
Validates data for a particular typesfield.

Private Method Summary

string _create_required_msg(array $data)
Create an error message for missing required field.
mixed get_error(string $fname)
Get any errors for a form element.
string _create_unique_msg(array $data)
Create an error message for non-unique "unique" field.
string _check_unique(array $data)
Checks to see whether the passed field is unique within the datatype.
string _validate(array $data)
Generic validation function.
mixed _process(array $data)
Generic (default) post-processor function.
string _validate_email(array $data)
Validates an email address.
string _validate_num(array $data)
Validates a number.
string _validate_pass2(array $data)
Validates a password.
mixed _include_processor(string $plugin_data, array &$data)
Include a post-processor script from a (php) file.
mixed _include_validator(string $plugin_data, array &$data)
Include a validator script from a (php) file.
mixed _invoke_class_validator( $data)
Invokes the class method for a specific validator.
mixed _invoke_class_processor( $data)
Invokes the class method for a specific post-processor.

Fields inherited from pxdb_confront

$_imported, $validator, $_upload_fields, $_params, $_widget_params, $_data, $data_name_structure, $param_name_structure, $widget_param_name_structure

Fields inherited from pxdb_data

$debug, $errors, $datatype, $auth, $tpl, $show_unapproved, $db, $user_minimal_columns

Private Field Summary

array $class_methods

array $type_validators
Array of validator functions for a field.
array $field_validators
Array of validator functions for a field type.
array $type_processors
Array of post-processor functions for a field type.
array $field_processors
Array of post-processor functions for a field.

Included files Summary, Type: include

$ppath Warning: documentation is missing.
$vpath Warning: documentation is missing.

Public Method Details

pxdb_validator

public void pxdb_validator()

 

Returns void


&singleton

public object pxdb_validator &singleton()

  Will create a new validator class only if one does not already exist.

Returns object pxdb_validator

or false on error.


set_validators_path

public void set_validators_path(string $path)

 

Parameter
string $path
The path to use for including validator scripts.
Returns void


register_type_validator

public void register_type_validator(string $type, mixed $function)

 

Parameter
string $type
The type of input to validate (e.g. 'url', 'ltxt' or 'primaryrel')
mixed $function
the name of the function. (or array of object reference + function)
Returns void


register_field_validator

public boolean register_field_validator(string $field, mixed $function, [ mixed $datatype ])

 

Parameter
string $field
The name of input field to validate (e.g. 'name', 'idnum')
mixed $function
the name of the function. (or array of object reference + function)
mixed $datatype = >>null<<
The datatype this field belongs to -- in case more than one dt has defined that field.
Returns boolean


register_type_processor

public void register_type_processor(string $type, mixed $function)

 

Parameter
string $type
The type of input to process (e.g. 'url', 'ltxt' or 'primaryrel')
mixed $function
the name of the function. (or array of object reference + function)
Returns void


register_field_processor

public boolean register_field_processor(string $field, mixed $function, [ mixed $datatype ])

 

Parameter
string $field
The name of input field to process (e.g. 'name', 'idnum')
mixed $function
the name of the function. (or array of object reference + function)
mixed $datatype = >>null<<
The datatype this field belongs to -- in case more than one dt has defined that field.
Returns boolean


process

public mixed process(int $tfid, string $fname, mixed $value)

 

Parameter
int $tfid
The pxdb_typesfield id.
string $fname
The fieldname.
mixed $value
The value to be processed.
Returns mixed

The error [hash array] that was produced or false if no error.


validate

public mixed validate(integer $tfid, string $fname, mixed $value)

  Sets a global array $pxdb[validation] that will be read in by a subsequent instantiation of this class.

Parameter
integer $tfid
The pxdb_typesfield id.
string $fname
The fieldname.
mixed $value
The value to be validated.
Returns mixed

The error [hash array] that was produced or false if no error.


Private Method Details

_create_required_msg

private string _create_required_msg(array $data)

 

Parameter
array $data
The data hash that is passed to validator functions.
Returns string


get_error

private mixed get_error(string $fname)

  Given the typesfield ID and fieldname, this function checks to see whether entered data meets up to specified expectations.

Parameter
string $fname
The array key to lookup for the error.
Returns mixed

A hash with error information -- or false if there is no error.


_create_unique_msg

private string _create_unique_msg(array $data)

 

Parameter
array $data
The data hash that is passed to validator functions.
Returns string

The [translated] error message.


_check_unique

private string _check_unique(array $data)

 

Parameter
array $data
The data hash that is passed to validator functions.
Returns string

The error message.


_validate

private string _validate(array $data)

 

Parameter
array $data
Returns string


_process

private mixed _process(array $data)

 

Parameter
array $data
Returns mixed

Post -processed value.


_validate_email

private string _validate_email(array $data)

 

Parameter
array $data
Hash of field properties
Returns string

Error found.


_validate_num

private string _validate_num(array $data)

 

Parameter
array $data
Hash of field properties
Returns string

Error found;


_validate_pass2

private string _validate_pass2(array $data)

 

Parameter
array $data
Hash of field properties
Returns string

Error found;


_include_processor

private mixed _include_processor(string $plugin_data, array &$data)

 

Parameter
string $plugin_data
The name of the processor plugin to include AND parameters.
array &$data
Hash of data to pass to validator function.
Returns mixed


_include_validator

private mixed _include_validator(string $plugin_data, array &$data)

 

Parameter
string $plugin_data
The name of the validator plugin to include and parameters.
array &$data
Hash of data to pass to validator function.
Returns mixed


_invoke_class_validator

private mixed _invoke_class_validator( $data)

 

Parameter
$data
Warning: documentation is missing.
Returns mixed

The error returned by class method or false.


_invoke_class_processor

private mixed _invoke_class_processor( $data)

 

Parameter
$data
Warning: documentation is missing.
Returns mixed

The new value returned by post-processor.


Private Field Details

$class_methods

private array $class_methods

>><<


$type_validators

private array $type_validators

>><<


$field_validators

private array $field_validators

>><<


$type_processors

private array $type_processors

>><<


$field_processors

private array $field_processors

>><<


Included Files, Type: include

$ppath

include( $ppath )


$vpath

include( $vpath )



Packageindex Classtrees Modulegroups Elementlist Report XML Files
Generated on Fri, 28 Apr 2006 19:07:22 -0400 by PHPDoc v1.5 www.phpdoc.de