Hi,
I noticed, that Zend_Form_Element does only set up a basic validator and
ignores other properties.
In detail:
I am working with Zend_Form and doing the same like described in
documentation example 23.12 [1].
I set up a translator in the init() method of "My_Form", which will
translate the "Zend_Validate_NotEmpty::IS_EMPTY" message for example.
For one element, I don't want that the default translator will be used.
If you would first set up the validator and pass it to the element, you
would call the validator's setDisableTranslator() method. But in the
described way, you use an configuration array, for example:
$this->addElement(new Zend_Form_Element('userid', array(
'required' => true,
'filters' => array('Int'),
'validators' => array(
array('NotEmpty', true, array(
'translatorDisabled' => true,
'messages' => array(
Zend_Validate_NotEmpty::IS_EMPTY => 'Invalid UserID specified!'
)
)
)
)
);
The problem is, that Zend_Form_Element only takes care about the "messages"
option.
Currently that's the way I solved the problem:
I extended Zend_Form_Element and overwrote
Zend_Form_Element:_loadValidator() this way:
protected function _loadValidator(array $validator)
{
$instance = parent::_loadValidator($validator);
if (isset($validator['options']))
{
if (isset($validator['options']['disableTranslator']))
{
$instance->setDisableTranslator($validator['options']['disableTranslator']);
unset($validator['options']['disableTranslator']);
}
}
return $instance;
}
Other not honored options might be "ObscureValue", "Translator"...
My questions are:
1) Am I doing something wrong? Did I miss something importan (I am new to
ZF)? Is there a better way?
2) If there isn't a better way and I am not doing something wrong, it's a
kind of bug for me - isn't it? So should I fill a bug report?
See also:
=========
[1] http://framework.zend.com/manual/en/zend.form.advanced.html
--
Regards,
Thomas