Fieldset
에는 Element\Radio
foo
및 Element\Text
bar
이 있습니다.Zend Framework 2에서 radion 버튼 요소의 선택된 옵션을 얻는 방법은 무엇입니까?
public function init()
{
$this->add(
[
'type' => 'radio',
'name' => 'foo',
'options' => [
'label' => _('foo'),
'value_options' => [
[
'value' => 'a',
'label' => 'a',
'selected' => true
],
[
'value' => 'b',
'label' => 'b'
]
]
]
...
]);
$this->add(
[
'name' => 'bar',
'type' => 'text',
'options' => [
'label' => 'bar',
...
],
...
]);
}
선택한 foo
옵션에 따라됩니다 bar
필드의 검증.
public function getInputFilterSpecification()
{
return [
'bar' => [
'required' => $this->get('foo')->getCheckedValue() === 'a',
...
],
];
}
그러나 어떤 방법 Radio#getCheckedValue()
가 없다 : 나는 foo
의 선택된 값을 얻을 수 있다면 그것은 쉽게 구현할 수 있습니다. 자, $this->get('foo')->getOptions()['value_options']
을 반복 할 수는 있지만 실제로는 유일한 방법입니까?
Fieldset#getInputFilterSpecification()
에서 선택한 옵션 Zend\Form\Element\Radio
을 얻는 방법은 무엇입니까?