Edit individual radio buttons in zend form view script

别说谁变了你拦得住时间么 提交于 2019-12-08 13:12:47

I have the same issue. There is no nice way to do this that I have found (circa ZF 1.10.8)

Matthew Weier O'Phinney had some advice on this page:

http://framework.zend.com/issues/browse/ZF-2977

But I find that approach cumbersome in practice. The original poster on that ticket had a good idea, and I think they should ultimately incorporate some nice way to do this along those lines.

But since there is no better way at the moment, I just follow Matthew's suggestion for now.

For my form I was working on, to render just one single radio button out of the group, I had to do this:

In my form class:

$radio = new Zend_Form_Element_Radio('MYRADIO');
$radio->addMultiOption('OPTION1', 'Option One')
      ->addMultiOption('OPTION2', 'Option Two');

$this->addElement($radio);

In my view script, just rendering OPTION1:

echo $this->formRadio(
    $this->form->MYRADIO->getFullyQualifiedName(),
    $this->form->MYRADIO->getValue(),
    null,
    array('OPTION1' => $this->form->MYRADIO->getMultiOption('OPTION1'))
);

That will render a <input type="radio" /> element, and an associated <label>. No other decorators will be rendered, which is a pain.

For your case, you will probably want to render your radio elements and other elements using the ViewScript view helper - so you can line all of the elements up amongst your own custom table markup as you described.

Figured this one out too. Just use

$this->element->getElment('myRadio')->getMultiOptions();

and it will return an array of the key/value options.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!