You can put a custom class on the field by adding 'class' => 'name'
to the array and CakePHP will put that class on the input.
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>.'
));
Produces:
<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>
You can apply custom styles to the input using '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>.'
));
Produces:
<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>
You can also apply custom styles or classes on the <div>
the input is grouped into and to the <label>
associated with the <input>
as well.
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'
)
));
Produces:
<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>
And finally, as @dave suggested, you can remove the <div>
or <label>
by setting them to false
and insert your own custom 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>';
Produces:
<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>
source documentation
(I've deleted some element attributes because they are specific to the database, tables and models used)