In addition to per-field configuration, each field can be assigned a set of validators and filters.
Zend\InputFilter\InputFilter
runs filters before validators, giving you the opportunity to
"cleanup" and normalize data.
The Zend\Filter component is used to accomplish the filtering phase of content validation.
Here is a list of the available filters:
Filters are executed prior to validation, allowing you to perform normalization tasks.
In this example we'll add a StringTrim
filter to the name field. To add a filter for a specific
field you need to click on the plus (+) button on the "filter" column:
Once this is in place, we'll issue a request to the contact service that looks like this:
POST /contact HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
{
"age": "34",
"email": "[email protected]",
"name": " Ralph Schindler "
}
And the response:
HTTP/1.1 201 Created
Content-Type: application/hal+json
Location: http://localhost:8000/contact/5
{
"_links": {
"self": {
"href": "http://localhost:8000/contact/5"
}
},
"age": "34",
"email": "[email protected]",
"id": 5,
"name": "Ralph Schindler",
"notes": null
}
As you will notice, name
was provided with leading and trailing whitespace, but the response field
does not contain the whitespace.