0
我有表單與集合。我附加驗證整個collecion - 我只是想檢查集合中的元素之間的某些關係的存在。 Zend Form Element Collection驗證作爲一個整體
它很好用。在數據錯誤的情況下 - 表單不會通過「isValid()」測試。
但有一個問題。 formElementErrors/getMessages沒有返回任何東西。 我做錯了什麼?
我的形式:
class Form implements InputFilterProviderInterface {
/**
* @return array
*/
public function getInputFilterSpecification()
{
return [
[
'name' => 'legend',
'required' => true,
'allowEmpty' => false,
'validators' => [
['name' => 'Callback', 'options' => [
'messages' => [
\Zend\Validator\Callback::INVALID_VALUE => 'Wrong',
],
'callback' => function ($values, $context=[]) {
return false;
},
]],
]
],
];
}
public function init()
{
$this->add(
[
'name' => 'legend',
'type' => 'Zend\Form\Element\Collection',
'options' => [
'label' => 'Legenda',
'count' => 2,
'should_create_template' => true,
'allow_add' => true,
'template_placeholder' => '__placeholder__',
'target_element' => [
'type' => 'Narzedzie\Form\Legenda\LegendyOpcjeFieldset',
],
],
]
);
}
}
,並查看:
$element = $NarzedzieForm->get('legend');
var_dump($element->getMessages()); // in case of error - empty array!
echo $this->formElementErrors($element); // in case of error - empty string
echo $this->formColleciton($element);
我敢肯定,這不是在回調錯誤 - 相同的情況下,如果我只回調「返回假/真」;我要去檢查INVALID_CALLBACK。那個foreach部分只是例如。 – 2014-10-07 12:50:41