2012-04-19 131 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)); 

享受