问题描述
我在使用CakePHP3的表单助手类时遇到问题。
I"m having trouble with CakePHP3's Form Helper class.
当我创建如下的文本输入字段时:
When I create a text input field like this:
echo $this->Form->input('fieldname');
当输入字段是required时,标签以粗体显示,这很好。
When the input field is "required", a label appears in bold. This is fine.
strong>选择字段:
However, when I create a select field like this:
echo $this->Form->select('fieldname', [1,2,3,4,5]);
我可以手动添加它:
echo $this->Form->label('fieldname');
但是在select是必填字段的情况下,字体不正确所需的标签显示为粗体,后面带有红色*)。我将其缩小到仅适用于嵌套标签标签的CSS(因此,当我创建标签标签时,它不在div标签内像文本输入的标签是)。
However in cases where the select is a required field, the font is not correct (required labels show up bold with a red * following them). I've narrowed this down to the CSS only applying to nested label tags (so when I create a label tag, it's not inside a div tag like the labels for the text inputs are).
我想避免手动插入HTML代码来实现我想要的结果,任何帮助将不胜感激! >
I'd like to avoid manually inserting HTML code to achieve my desired result, any help would be appreciated!
推荐答案
<?= $this->Form->input('fieldName', ['type' => 'select', 'options' => ['0' => 'Option1' , '1' => 'Option2'], 'empty' => __('(choose one)'), 'label' => __('LabelName')]);?>
或
$sizes = ['s' => 'Small', 'm' => 'Medium', 'l' => 'Large'];
<?= $this->Form->input('fieldName', ['type' => 'select', 'options' => $sizes, 'default' => 'm', 'label' => __('LabelName')]);?>
这篇关于选择表单助手的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!