【问题标题】:Form fields and label position in Zend framework 2Zend框架2中的表单字段和标签位置
【发布时间】:2013-01-11 00:47:03
【问题描述】:
我有一个使用 Zend\Form\Annotation 创建的 Zend 表单。我正在使用以下代码生成 HTML:
echo $this->form()->openTag($form);
echo $this->formCollection($form);
echo $this->form()->closeTag();
问题是标签被放置在输入文本字段之前,如下所示:
标签:输入文本框
我想这样做:
标签:
输入文本框
如何格式化我的标签以获得我想要的位置?
【问题讨论】:
标签:
forms
label
zend-framework2
【解决方案1】:
我要做的是使用单独的元素打印而不是使用 formCollection 方法,如下所示:
<dl class="zend_form">
<?php echo $this->formElementErrors($form->get('identity')) ?>
<dt><?php echo $this->formLabel($form->get('identity')) ?></dt>
<dd><?php echo $this->formInput($form->get('identity')) ?></dd>
<dt><?php echo $this->formLabel($form->get('credential')) ?></dt>
<dd><?php echo $this->formInput($form->get('credential')) ?></dd>
<?php if ($this->redirect): ?>
<input type="hidden" name="redirect" value="<?php echo $this->redirect ?>" />
<?php endif ?>
<dd><?php echo $this->formButton($form->get('submit')) ?></dd>
</dl>
【解决方案2】:
你可以使用 css:
label {
display: block;
}
【解决方案3】:
只需在注释中为元素指定一个 id,例如 @Annotation\Attributes({"id" : "id"})