2012-04-19 132 views
2

我想使用单选按钮使用表单助手。单选按钮有一个无线电元素和一个标签。我默认显示:标签元素块。我想给一个类指定单选按钮的标签,以便我可以为它分配一个内联块。Cakephp表单单选按钮标签类

$attributes = array('legend' => false, 'label' => array('class' => 'radioBtn')); 
echo $this->Form->radio('gender', $options, $attributes); 

我如何可以指定一个类来选择

回答

5

的标签,通过看形式 - >无线()方法的代码,似乎没有任何与属于标签属性。

但修改这些标签的显示,你可以使用一个周围div

echo '<div class="inline_labels">'; 
echo $this->Form->radio('gender', $options, $attributes); 
echo '</div>'; 

,并使用CSS这样的:

.inline_labels label 
{ 
    display: inline-block; 
} 
+0

是标签现在已经很好地在一行。只有很糟糕,他们已经失去了与单选按钮的连接。 – 2014-12-16 10:57:37

1

如何使用FormHelper::label(string $fieldName, string $text, array $options) 你可以定义标签类在选项数组中,所以(举例):

echo $options = array(/* relevant stuff goes here */); 
echo $attributes = array(/* relevant stuff goes here */); 
echo $this->Form->radio('gender', $options, $attributes); 
echo $this->Form->label('gender', 'Text of your label', array('label'=>'radioBtn')) 

对我来说来源CakePHP Cookbook on FormHelper

0

工作:

// Add your own label with CSS class 
$opts = array('1' => "<label class='myCSS'>My first option</label>", "2" => "<label class='myCSS'>My second option</label>"); 

// Put label param to false 
echo $this->Form->input('my-input', array('type' => 'radio', 'label' => false, 'options' => $opts, 'legend' => false)); 

享受