People have voiced the need for form input filtering various times. Filtering could be added to the Form component very easily by creating an (optional) extension that enables the following API:
$builder->add('content', 'textarea', array(
// a single filter or an array of filters
'filters' => new StripTags(),
));
The big question is which library to use for filtering. Upon short research, I came upon two existing alternatives:
- Zend\Filter
- appears mature
- potentially brings in other ZF2 baggage, which I don't care about once ZF2 supports Composer properly and unless the baggage creates further disadvantages
- DMS-Filter
- very young
- supports annotation-based filtering in POPOs
Does anyone know further filtering libraries? Does anyone have experience with Zend\Filter in non-ZF(2) projects?
Comparison Sheet
| Zend\Filter |
DMS-Filter |
Comment |
| Alnum |
Alnum |
both support Unicode, Zend has special treatment for Japanese, Chinese and Korean |
| Alpha |
|
|
| Boolean |
Boolean |
DMS does a simple cast, Zend's implementation is more complicated, but supports localized "yes" and "no" as well as leaving the original value unchanged unless it evaluates to false (use case?) |
| Callback |
|
|
| Digits |
|
|
| File\LowerCase |
|
|
| File\Rename |
|
|
| File\UpperCase |
|
|
|
Float |
|
| HtmlEntities |
|
|
| Int |
Int |
|
| PregReplace |
|
supports Unicode |
| StringToLower |
ToLower |
both support Unicode |
| StringToUpper |
ToUpper |
both support Unicode |
| StringTrim |
Trim |
both allow the specification of a character list to be trimmed |
| StripNewlines |
StripNewlines |
|
| StripTags |
StripTags |
Zend allows to specify allowed tags, attributes and comments; DMS only allowed tags (using `strip_tags` internally). |
| Not a filter, but a transformer |
| BaseName |
|
|
| Compress |
|
supports BZ2, GZ, LZF, RAR, TAR and ZIP |
| Decompress |
|
see Compress |
| Decrypt |
|
supports MCrypt and OpenSSL |
| Dir |
|
|
| Encrypt |
|
see Decrypt |
| File\Decrypt |
|
see Decrypt |
| File\Encrypt |
|
see Decrypt |
| Null |
|
|
| RealPath |
|
|
| Word\CamelCaseToDash |
|
|
| Word\CamelCaseToSeparator |
|
|
| Word\CamelCaseToUnderscore |
|
|
| Word\DashToCamelCase |
|
|
| Word\DashToSeparator |
|
|
| Word\DashToUnderscore |
|
|
| Word\SeparatorToCamelCase |
|
|
| Word\SeparatorToDash |
|
|
| Word\SeparatorToSeparator |
|
|
| Word\UnderscoreToCamelCase |
|
|
| Word\UnderscoreToDash |
|
|
| Word\UnderscoreToSeparator |
|
|
People have voiced the need for form input filtering various times. Filtering could be added to the Form component very easily by creating an (optional) extension that enables the following API:
The big question is which library to use for filtering. Upon short research, I came upon two existing alternatives:
Does anyone know further filtering libraries? Does anyone have experience with Zend\Filter in non-ZF(2) projects?
Comparison Sheet