Provides access to form variables.
This class allows you to retrieve input variables from the request in a safe way, by applying filters to allow only wanted data into your application. It works by passing an array that describes your form definition to the constructor of the class. The constructor will then initialize the class with properties that contain the value of your request's input fields.
Example:
Source for this file: /UserInput/src/input_form.php
Version: | //autogentag// |
DEF_ELEMENT_NO_DEFINITION_ELEMENT
= 3
|
|
DEF_EMPTY
= 2
|
|
DEF_FIELD_NAME_BROKEN
= 8
|
|
DEF_NOT_REQUIRED_OR_OPTIONAL
= 5
|
|
DEF_NO_ARRAY
= 1
|
|
DEF_UNSUPPORTED_FILTER
= 7
|
|
DEF_WRONG_FLAGS_TYPE
= 6
|
|
INVALID
= 1
|
|
VALID
= 0
|
string | read |
$formFields
There is a read-only property for each field that is defined as input field. |
protected array |
$propertyValues
Contains the values of the input variables. The key for each array element is the field name, and the value associated with this key is the property's value. This array does not have an entry for input fields that do not have valid data. |
public static bool |
hasGetData(
)
Returns whether there is GET data available |
public static bool |
hasPostData(
)
Returns whether there is POST data available |
public static array|bool |
validateDefinition(
$definition
)
Validates the definition array $definition. |
public ezcInputForm |
__construct(
$inputSource
, $definition
, [ $characterEncoding
= null] )
Constructs a new ezcInputForm for $inputSource with $definition. |
public array(string) |
getInvalidProperties(
)
Returns a list with all properties having invalid data. |
public array(string) |
getOptionalProperties(
)
Returns a list with all optional properties. |
public array(string) |
getRequiredProperties(
)
Returns a list with all required properties. |
public string |
getUnsafeRawData(
$fieldName
)
Returns RAW input variable values for invalid field $fieldName. |
public array(string) |
getValidProperties(
)
Returns a list with all properties that have valid data. |
public bool |
hasInputField(
$fieldName
)
Returns whether the optional field $fieldName exists. |
public bool |
hasValidData(
$fieldName
)
Returns whether the filters for required field $fieldName returned valid data. |
public bool |
isValid(
)
Returns whether all the input elements were valid or not. |
Returns whether there is GET data available
Returns whether there is POST data available
Validates the definition array $definition.
Before reading the values from the input source, the definition array can be validated by this method to check whether all necessary elements are correctly formed.
With the following code you can check whether the definition is valid:
Name | Type | Description |
---|---|---|
$definition |
array |
Constructs a new ezcInputForm for $inputSource with $definition.
This method constructs a new ezcInputForm with three parameters. The $inputSource parameter selects the input source and should be one of the constants INPUT_GET, INPUT_POST or INPUT_COOKIE. The $definition parameter is an array of ezcInputFormDefinitionElement items and determines which input variables make up this form (see the example at the top of this class). The last parameter, $characterEncoding is the character encoding to use while retrieving input variable data. This parameter has currently no function as it will depend on PHP 6 functionality which does not exist yet in the input filter extension.
Name | Type | Description |
---|---|---|
$inputSource |
int | |
$definition |
array(ezcInputFormDefinitionElement) | |
$characterEncoding |
string |
Type | Description |
---|---|
ezcInputFormInvalidDefinitionException |
when the definition array is invalid or when the input source was invalid. |
ezcInputFormVariableMissingException |
when one of the required input variables is missing. |
Returns a list with all properties having invalid data.
Returns a list with all optional properties.
Returns a list with all required properties.
Returns RAW input variable values for invalid field $fieldName.
The return value of this function can be used to prefill forms on the next request. It will only work for invalid input fields, as for valid input fields you should never have to get to the original RAW data. In the case a $fieldName is passed that has valid data, an ezcInputFormException will be thrown.
Name | Type | Description |
---|---|---|
$fieldName |
string |
Type | Description |
---|---|
ezcInputFormFieldNotFoundException |
when trying to get data from a property that does not exist. |
ezcInputFormValidDataException |
when trying to get unsafe raw data from a input field with valid data. |
Returns a list with all properties that have valid data.
Returns whether the optional field $fieldName exists.
Name | Type | Description |
---|---|---|
$fieldName |
string |
Returns whether the filters for required field $fieldName returned valid data.
Name | Type | Description |
---|---|---|
$fieldName |
string |
Returns whether all the input elements were valid or not.