您可以通过添加到数组中来在字段上放置一个自定义类'class' => 'name'
,CakePHP 会将该类放在输入中。
echo $form->input(
'terms',
array(
'type' => 'checkbox',
'class' => 'some-class-name',
'label' => 'I have read and accept the <a target="_blank" href="/terms">Terms</a>.'
));
产生:
<div class="input checkbox">
<input type="hidden" name="" id="" value="0">
<input type="checkbox" name="" class="some-class-name" value="1" id="">
<label for="">I have read and accept the <a target="_blank" href="/terms">Terms</a>.</label>
</div>
您可以使用将自定义样式应用于输入'style' => 'some:style;'
echo $form->input(
'terms',
array(
'type' => 'checkbox',
'style' => 'width:200px;',
'label' => 'I have read and accept the <a target="_blank" href="/terms">Terms</a>.'
));
产生:
<div class="input checkbox">
<input type="hidden" name="" id="" value="0">
<input type="checkbox" name="" style="width:200px;" value="1" id="">
<label for="">I have read and accept the <a target="_blank" href="/terms">Terms</a>.</label>
</div>
您还可以<div>
在输入上应用自定义样式或类,并将其分组到与<label>
关联的关联中<input>
。
echo $form->input(
'terms',
array(
'type' => 'checkbox',
'label' => array(
'text' => 'I have read and accept the <a target="_blank" href="/terms">Terms</a>.',
'style' => 'width:200px;',
'class' => 'class-for-label'
),
'div' => array(
'style' => 'width:200px;',
'class' => 'class-for-div'
)
));
产生:
<div class="class-for-div" style="width:200px;">
<input type="hidden" name="" id="" value="0">
<input type="checkbox" name="" value="1" id="">
<label for="" style="width:200px;" class="class-for-label">I have read and accept the <a target="_blank" href="/terms">Terms</a>.</label>
</div>
最后,正如@dave 建议的那样,您可以删除<div>
or<label>
将它们设置为false
并插入您自己的自定义 HTML。
echo '<div class="input checkbox">';
echo $form->input(
'terms',
array(
'type' => 'checkbox',
'label' => false,
'div' => false
));
echo '<label>I have read and accept the <a target="_blank" href="/terms">Terms</a>.</label>';
echo '</div>';
产生:
<div class="input checkbox">
<input type="hidden" name="" id="" value="0">
<input type="checkbox" name="" value="1" id="">
<label>I have read and accept the <a target="_blank" href="/terms">Terms</a>.</label>
</div>
源文档
(我删除了一些元素属性,因为它们特定于所使用的数据库、表和模型)