
Provides validation routines for standalone forms, such as contact forms
1.0.0b12 | Fixed some method signatures 8/24/11 |
---|---|
1.0.0b11 | Fixed addCallbackRule() to be able to handle multiple rules per field 6/2/11 |
1.0.0b10 | Fixed addRegexRule() to be able to handle multiple rules per field 8/30/10 |
1.0.0b9 | Enhanced all of the add fields methods to accept one field per parameter, or an array of fields 6/24/10 |
1.0.0b8 | Added/fixed support for array-syntax fields names 6/9/10 |
1.0.0b7 | Added the ability to pass an array of replacements to addRegexReplacement() and addStringReplacement() 5/31/10 |
1.0.0b6 | BackwardsCompatibilityBreak - moved one-or-more required fields from addRequiredFields() to addOneOrMoreRule(), moved conditional required fields from addRequiredFields() to addConditionalRule(), changed returned messages array to have field name keys - added lots of functionality 5/26/10 |
1.0.0b5 | Added the $return_messages parameter to validate() and updated code for new fValidationException API 9/17/09 |
1.0.0b4 | Changed date checking from strtotime() to fTimestamp for better localization support 6/1/09 |
1.0.0b3 | Updated for new fCore API 2/16/09 |
1.0.0b2 | Added support for validating date and URL fields 1/23/09 |
1.0.0b | The initial implementation 6/14/07 |
Composes text using fText if loaded
string compose( string $message, mixed $component [, ... ] )
string | $message | The message to compose |
mixed | $component [, ... ] | A string or number to insert into the message |
The composed and possible translated message
Returns TRUE for non-empty strings, numbers, objects, empty numbers and string-like numbers (such as 0, 0.0, '0')
boolean stringlike( mixed $value )
mixed | $value | The value to check |
If the value is string-like
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
All requests that hit this method should be requests for callbacks
callback __get( string $method )
string | $method | The method to create a callback for |
The callback for the method requested
Adds fields to be checked for 1/0, t/f, true/false, yes/no
fValidation addBooleanFields( string $field [, ... ] )
fValidation addBooleanFields( array $fields )
string | $field [, ... ] | A field that should contain a boolean value |
array | $fields | Any number of fields that should contain a boolean value |
The validation object, to allow for method chaining
Adds a callback validation of a field, with a custom error message
fValidation addCallbackRule( string $field, callback $callback, string $message )
string | $field | The field to test with the callback |
callback | $callback | The callback to test the value with - this callback should accept a single string parameter and return a boolean |
string | $message | The error message to return if the regular expression does not match the value |
The validation object, to allow for method chaining
Adds fields to be conditionally required if another field has any value, or specific values
fValidation addConditionalRule( string|array $main_fields, mixed $conditional_values, string|array $conditional_fields )
string|array | $main_fields | The fields(s) to check for a value |
mixed | $conditional_values | If NULL, any value in the main field(s) will trigger the conditional field(s), otherwise the value must match this scalar value or be present in the array of values |
string|array | $conditional_fields | The field(s) that are to be required |
The validation object, to allow for method chaining
Adds form fields to the list of fields to be blank or a valid date
Use addRequiredFields() disallow blank values.
fValidation addDateFields( string $field [, ... ] )
fValidation addDateFields( array $fields )
string | $field [, ... ] | A field that should contain a valid date |
array | $fields | Any number of fields that should contain a valid date |
The validation object, to allow for method chaining
Adds form fields to the list of fields to be blank or a valid email address
Use addRequiredFields() disallow blank values.
fValidation addEmailFields( string $field [, ... ] )
fValidation addEmailFields( array $fields )
string | $field [, ... ] | A field that should contain a valid email address |
array | $fields | Any number of fields that should contain a valid email address |
The validation object, to allow for method chaining
Adds form fields to be checked for email injection
Every field that is included in email headers should be passed to this method.
fValidation addEmailHeaderFields( string $field [, ... ] )
fValidation addEmailHeaderFields( array $fields )
string | $field [, ... ] | A field to be checked for email injection |
array | $fields | Any number of fields to be checked for email injection |
The validation object, to allow for method chaining
Add a file upload field to be validated using an fUpload object
fValidation addFileUploadRule( string $field, mixed $index, fUpload $uploader )
fValidation addFileUploadRule( string $field, fUpload $uploader )
string | $field | The field to validate |
mixed | $index | The index for array file upload fields |
fUpload | $uploader | The uploader to validate the field with |
The validation object, to allow for method chaining
Adds fields to be checked for float values
fValidation addFloatFields( string $field [, ... ] )
fValidation addFloatFields( array $fields )
string | $field [, ... ] | A field that should contain a float value |
array | $fields | Any number of fields that should contain a float value |
The validation object, to allow for method chaining
Adds fields to be checked for integer values
fValidation addIntegerFields( string $field [, ... ] )
fValidation addIntegerFields( array $fields )
string | $field [, ... ] | A field that should contain an integer value |
array | $fields | Any number of fields that should contain an integer value |
The validation object, to allow for method chaining
Adds a rule to make sure at least one field of multiple has a value
fValidation addOneOrMoreRule( string $field, string $field_2 [, ... ] )
string | $field | One of the fields to check for a value |
string | $field_2 [, ... ] | Another field to check for a value |
The validation object, to allow for method chaining
Adds a rule to make sure at exactly one field of multiple has a value
fValidation addOnlyOneRule( string $field, string $field_2 [, ... ] )
string | $field | One of the fields to check for a value |
string | $field_2 [, ... ] | Another field to check for a value |
The validation object, to allow for method chaining
Adds a call to preg_replace() for each message
Replacement is done right before the messages are reordered and returned.
If a message is an empty string after replacement, it will be removed from the list of messages.
fValidation addRegexReplacement( string $search, string $replace )
fValidation addRegexReplacement( array $replacements )
string | $search | The PCRE regex to search for - see http://php.net/pcre for details |
string | $replace | The string to replace with - all $ and \ are used in back references and must be escaped with a \ when meant literally |
array | $replacements | An associative array with keys being regular expressions to search for and values being the string to replace with |
The validation object, to allow for method chaining
Adds regular expression validation of a field, with a custom error message
fValidation addRegexRule( string $field, string $regex, string $message )
string | $field | The field to test with the regular expression |
string | $regex | The PCRE regex to search for - see http://php.net/pcre for details |
string | $message | The error message to return if the regular expression does not match the value |
The validation object, to allow for method chaining
Adds form fields to be required
fValidation addRequiredFields( string $field [, ... ] )
fValidation addRequiredFields( array $fields )
string | $field [, ... ] | A field to require a value for |
array | $fields | Any number of fields to require a value for |
The validation object, to allow for method chaining
Adds a call to str_replace() for each message
Replacement is done right before the messages are reordered and returned.
If a message is an empty string after replacement, it will be removed from the list of messages.
fValidation addStringReplacement( string $search, string $replace )
fValidation addStringReplacement( array $replacements )
string | $search | The string to search for |
string | $replace | The string to replace with |
array | $replacements | An associative array with keys being strings to search for and values being the string to replace with |
The validation object, to allow for method chaining
Adds form fields to the list of fields to be blank or a valid URL
Use addRequiredFields() disallow blank values.
fValidation addURLFields( string $field [, ... ] )
fValidation addURLFields( array $fields )
string | $field [, ... ] | A field that should contain a valid URL |
array | $fields | Any number of fields that should contain a valid URL |
The validation object, to allow for method chaining
Adds a rule to make sure a field has one of the specified valid values
A strict comparison will be made from the string request value to the array of valid values.
fValidation addValidValuesRule( string $field, array $valid_values )
string | $field | The field to check the value of |
array | $valid_values | The valid values |
The validation object, to allow for method chaining
Allows overriding the default name used for a field in the error message
By default, all fields are referred to by the field name run through fGrammar::humanize(). This may not be correct for acronyms or complex field names.
fValidation overrideFieldName( string $field, string $name )
fValidation overrideFieldName( array $field_names )
string | $field | The field to set the custom name for |
string | $name | The custom name for the field |
array | $field_names | An associative array of custom field names where the keys are the field and the values are the names |
The validation object, to allow for method chaining
Allows setting the order that the individual errors in a message will be displayed
All string comparisons during the reordering process are done in a case-insensitive manner.
fValidation setMessageOrder( string $match, string $match_2=NULL [, ... ] )
string | $match | The string match to order first |
string | $match_2 [, ... ] | The string match to order second |
The validation object, to allow for method chaining
Checks for required fields, email field formatting and email header injection using values previously set
void|array validate( boolean $return_messages=FALSE, boolean $remove_field_names=FALSE )
boolean | $return_messages | If an array of validation messages should be returned instead of an exception being thrown |
boolean | $remove_field_names | If field names should be removed from the returned messages, leaving just the message itself |
If $return_messages is TRUE, an array of validation messages will be returned