我希望能够设置标签位置:
我有一个表单,就像这样构建:
<?php
$form = $this->form;
$form->setAttribute('action', $this->url());
$form->prepare();
echo $this->form()->openTag($form);
?>
<?php $fooFieldset = $form->get('foo'); ?>
<div id="fieldset-foo" class="fieldset-container col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php echo $this->translate($fooFieldset->getLabel()); ?></h3>
</div>
<div class="panel-body">
<?php foreach ($fooFieldset as $element) : ?>
<div class="form-group <?php if($this->formElementErrors($element)) echo 'error' ?>">
<?php $element->setOption('label_position', FormRow::LABEL_PREPEND); /* not working! */ ?>
<label><?php echo $this->translate($element->getLabel()); ?></label>
<div>
<?php $element->setAttribute('class', 'form-control'); ?>
<?php echo $this->formElement($element); ?>
<?php if ($this->formElementErrors($element)) : ?>
<div class="message-error"><?php echo $this->formElementErrors($element) ?></div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<!-- futher fieldsets -->
<!-- fields without fieldsets -->
<?php
echo $this->form()->closeTag($form);
?>
这意味着,我没有呼叫formRow(...)
或formMultiCheckbox(...)
,也无法通过这种方式配置label_position
。直接在元素($element->setOption('label_position', FormRow::LABEL_PREPEND)
)上设置选项根本不起作用 - 既不是整个元素也不是复选框/单选按钮。
如何让它工作并设置标签位置(1.对于整个元素; 2.对于复选框/单选按钮)?