ZF-6478: Improve Zend_Filter_Input capabilities

Issue Type: Improvement Created: 2009-04-30T05:26:07.000+0000 Last Updated: 2012-11-20T20:53:08.000+0000 Status: Closed Fix version(s): Reporter: Leandro Rodrigues Chaves (leandrorc) Assignee: None Tags: - Zend_Filter_Input

Related issues: Attachments:


As recommended by Thomas Weidner, in issue #ZF-6457, i would like to propose this improvement for Zend_Filter_Input. In #ZF-6457, i wrote about problems when using Zend_Filter_Input to filtering and validating operations using only one instance of Zend_Filter_Input, because the order of the things. So, i wrote:

"Ok. Let's make the things clear. A normal register process works the following way: 1 - The user types his name and date of birth in a form. Let's suppose the date field is in format "d/m/Y". 2 - The user clicks on the submit button. Then i use Zend_Filter_Input to make data processing. The problem is: how could i use Zend_Filter_Input to filter and validate this date?"

And Thomas Weidner wrote:

"First: Validate the input and look if it conforms your needs. Second: Filter the validated and correct value for further processing for your application.

The thing is: It would make no sense to filter/change the input when it's not valid."

Using Zend_Filter_Input in only one execution have some problems. For example, if a user enter with the value (1,500.00) in a number field and submits the form, we could have the following validation rules to apply in Zend_Filter_Input:

<pre class="highlight">
$validators = array( 'salary' => array('Float', array('Between', 0, 99999999.99) );

But, making validation before filtering, Float validation will pass (because in 1.8 Zend_Validate_Float supports locale), but the Between validation won't. I'm not sure about the best solution to make these things with only one instance of Zend_Filter_Input, maybe we could define a chain combining filters and validators, something like:

<pre class="highlight">
$chain = array(
    'filters' => array(
        'name' => 'StringTrim',
        'biografy' => array('StringTrim', 'StripTags'),
        'birth_date' => 'Date'
    'validators' => array(
        'name' => array('notEmpty', 'Alnum', array('StringLength', 1, 100)),
        'biografy' => array(array('StringLength', 0, 1000)),
        'salary' => 'Float',
        'birth_date' => 'ToDateObject', // Future String to Zend_Date converter
    'filters' => array(
        'salary' => new Zend_Filter_LocalizedToNormalized(array('precision' => 2))
    'validators' => array(
        'salary' => array(array('Between', 0, 99999999.99)),
        'birth_date' => array( 'DateGreaterThan', $date ) // Future Zend_Date object validator

$input = Zend_Filter_Input(null, null, $data, $options);

Well, that's my idea. The solution can be a bit immature yet. But the idea is that we could have as many as possible data filtering and processing using Zend_Filter_Input.


Posted by old of Satoru Yoshida ( on 2009-05-22T21:37:21.000+0000

set component and auto reassign

Posted by Jon Whitcraft (sidhighwind) on 2009-05-23T07:43:49.000+0000

I am wondering if this should be a proposal as it's changing the way the Filter_Input works.

Posted by Leandro Rodrigues Chaves (leandrorc) on 2009-05-23T08:05:14.000+0000

Yeah, maybe a new component called Zend_Filter_Input_Chain, or just a conditional in Zend_Filter_Input::process() method to consider a chain of filters and validators.

Posted by Rob Allen (rob) on 2012-11-20T20:53:08.000+0000

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.