0

我正在Zend\Form\Element\MultiCheckbox使用Zend\Form\View\Helper\FormMultiCheckbox

MyFieldset.php

// namespace ...;
// use ....;
class MyFieldset extends Fieldset
{
    // ...
    public function init()
    {
        parent::init();
        $this->add(
            [
                'type' => 'multi_checkbox',
                'name' => 'mymulticheckbox',
                'options' => [
                    'label' => _('global label'),
                    'label_attributes' => [
                        'class' => 'col-md-3',
                    ],
                    'value_options' => [
                        [
                            'value' => 'foo',
                            'label' => 'FOO',
                        ],
                        [
                            'value' => 'bar',
                            'label' => 'BAR',
                        ],
                        [
                            'value' => 'buz',
                            'label' => 'BUZ',
                        ],
                    ]
                ],
            ]
        );
    }
    // ...
}

myform.phml

use Zend\Form\View\Helper\FormMultiCheckbox;
echo $this->formMultiCheckbox($myFieldset->get('mymulticheckbox'), FormMultiCheckbox::LABEL_PREPEND);

它可以工作,但global label不显示“ ”。当我使用 时,它会显示出来Zend\Form\View\Helper\FormElement,但FormMultiCheckbox似乎忽略了“全局label”。

如何FormMultiCheckbox显示label复选框列表?

4

1 回答 1

0

你试过用formRow(). 对我来说它有效。这似乎没有在formMultiCheckbox(). 请参阅行182-193、文件zend-form/src/View/Helper/FormRow.php

// Multicheckbox elements have to be handled differently as the HTML standard does not allow nested
// labels. The semantic way is to group them inside a fieldset
if ($type === 'multi_checkbox'
    || $type === 'radio'
    || $element instanceof MonthSelect
    || $element instanceof Captcha
) {
    $markup = sprintf(
        '<fieldset><legend>%s</legend>%s</fieldset>',
        $label,
        $elementString
    );
于 2016-04-30T14:15:29.940 回答