Label for Select Form Helper

荒凉一梦 提交于 2019-12-12 03:47:00

问题


I"m having trouble with CakePHP3's Form Helper class.

When I create a text input field like this:

echo $this->Form->input('fieldname');

When the input field is "required", a label appears in bold. This is fine.

However, when I create a select field like this:

echo $this->Form->select('fieldname', [1,2,3,4,5]);

The select field is created however there is no label at all. I can add it manually using:

echo $this->Form->label('fieldname');

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).

I'd like to avoid manually inserting HTML code to achieve my desired result, any help would be appreciated!


回答1:


<?= $this->Form->input('fieldName', ['type' => 'select', 'options' => ['0' => 'Option1' , '1' => 'Option2'], 'empty' => __('(choose one)'), 'label' => __('LabelName')]);?>

or

$sizes = ['s' => 'Small', 'm' => 'Medium', 'l' => 'Large'];

<?= $this->Form->input('fieldName', ['type' => 'select', 'options' => $sizes, 'default' => 'm', 'label' => __('LabelName')]);?>


来源:https://stackoverflow.com/questions/37674682/label-for-select-form-helper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!