Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: Next Minor Release
-
Component/s: Zend_Filter_Input
-
Labels:None
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 <fieldName> => <defaultValue> 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 '*' => <value> is used as a default field value for all rule fields,
<key> => <value> pair overrides universal default rule:
// 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;
)
);
// 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);
)
);
// 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));
)
);
// 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);
)
);
Issue Links
| This issue is duplicated by: | ||||
| ZF-7471 | Zend_Filter_Input::DEFAULT_VALUE setting can't be array |
|
|
|