简体   繁体   中英

How can I add in CakePHP’s radio buttons to the label of each option a class?

In my CakePHP 2.3 Application I have a radio button group that contains 3 options:

$this->Form->radio('order', array(
'asc' => 'Ascending', 
'desc' => 'Descending',
'random' => 'Random'
), array('legend' => false)); ?>

The form-helper above generates the following html-code:

<input id="MyFormOrder_" type="hidden" value="" name="data[MyForm][order]">
<input id="MyFormRandomAsc" type="radio" value="asc" name="data[MyForm][order]">
<label for="MyFormRandomAsc">Ascending</label>
<input id="MyFormRandomDesc" type="radio" value="desc" name="data[MyForm][order]">
<label for="MyFormRandomDesc">Descending</label>
<input id="MyFormRandomRandom" type="radio" value="random" name="data[MyForm][order]">
<label for="MyFormRandomRandom">Random</label>

How can I add a css-class to only one of these labels via form helper?

I'm not certain FormHelper will accomplish what you want. In past projects I have resorted to using jQuery to assign a class to certain elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM