associated array elements in zend form

后端 未结 2 633
囚心锁ツ
囚心锁ツ 2021-01-24 00:11

Been trying to find a solution for this for a while with not much luck...

Need to render a form with an array of checkboxes each having an associated textbox.

gi

相关标签:
2条回答
  • 2021-01-24 00:26

    Can't be done without custom elements. I'd suggest watching http://www.zendcasts.com/writing-composite-zend_form-elements/2010/03/

    0 讨论(0)
  • 2021-01-24 00:35

    just create a custom decorator, extends from Zend_Form_Decorator_Abstract and define the function render, which returns the html that you define inside, for example you can do:

    $html = ''; // some code html
    $i = 0;
    foreach ($element->getMultiOptions() as $value => $label){
        $html .= '<label><input type="checkbox" name="'.$element->getName().'[]" id="'$element->getName()'-'.$i.'" value="'.$value.'" />'.$label.'</label>';
        $i++;
    }
    return $html;
    
    0 讨论(0)
提交回复
热议问题