Issues

ZF-6763: Zend_Filter_Input doesn't allow to use arrays as a default value for specified field.

Issue Type: Bug Created: 2009-05-21T04:23:01.000+0000 Last Updated: 2012-08-31T08:43:55.000+0000 Status: Open Fix version(s): Reporter: Alexander Veremyev (alexander) Assignee: Thomas Weidner (thomas) Tags: - Zend_Filter_Input

Related issues: - ZF-7471

Attachments:

Description

Zend_Filter_input allows to set default value, used for missing fields.

If value is scalar, it's used as a default value for all fields. If value is an array, it's used as => pairs (see Zend_Filter_Input::_validateRule() for details).

So it's not possible to use arrays as a default value for all rule fields even it's one field within a rule.

My offer is to use the following algorithm: if rule has only one field, default value is used even it's an array or not. if rule has several fields, scalar values used as a default values for all fields array is used as a list of default values and special pair '*' => is used as a default field value for all rule fields, => pair overrides universal default rule:

<pre class="highlight">
// field2 and field3 will be set to $value2
$data = array('field1' => $value1);
$validators = array(
    'ruleq'   => array(
        'MyCoolValidator',
        Zend_Filter_Input::self::FIELDS => array('field1', 'field2', 'field3')
        Zend_Filter_Input::self::DEFAULT_VALUE => $value2;
    )
);



<pre class="highlight">
// field2 and field3 will be set to $value2
$data = array('field1' => $value1);
$validators = array(
    'ruleq'   => array(
        'MyCoolValidator',
        Zend_Filter_Input::self::FIELDS => array('field1', 'field2', 'field3')
        Zend_Filter_Input::self::DEFAULT_VALUE => array('*' => $value2);
    )
);



<pre class="highlight">
// field2 and field3 will be set to array($value2)
$data = array('field1' => $value1);
$validators = array(
    'ruleq'   => array(
        'MyCoolValidator',
        Zend_Filter_Input::self::FIELDS => array('field1', 'field2', 'field3')
        Zend_Filter_Input::self::DEFAULT_VALUE => array('*' => array($value2));
    )
);



<pre class="highlight">
// field2 will be set to $value2, field1 and field3 will be set to $value3
$data = array();
$validators = array(
    'ruleq'   => array(
        'MyCoolValidator',
        Zend_Filter_Input::self::FIELDS => array('field1', 'field2', 'field3')
        Zend_Filter_Input::self::DEFAULT_VALUE => array('field2' => $value2, '*' => $value3);
    )
);

Comments

No comments to display

Have you found an issue?

See the Overview section for more details.

Copyright

© 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.

Contacts