2013-02-19 3 views
6

Wie füge ich einzelne Attribute zu Radiobuttons hinzu? Soweit ich das beurteilen kann, erlaubt CakePHP nur das Hinzufügen der gleichen (begrenzten) Attribute zu allen Optionsfeldern in der Gruppe.CakePHP - Wie Attribute zu einzelnen Radio-Buttons hinzufügen?

Irgendwelche Ideen, wie man das zum Beispiel erzeugt?

<input type="radio" checked="checked" value="0" name="data[MyModel][field]" id="custom-id-1" class="custom-class-1" data-something="test1"> 
<label for="custom-id-1">Test 1</label> 
<input type="radio" checked="checked" value="0" name="data[MyModel][field]" id="custom-id-2" class="custom-class-2" data-something="test2"> 
<label for="custom-id-2">Test 2</label> 

Antwort

-1

echo $this->Form->input('title', array('type' => 'radio', 'class' => 'custom-class', 'atributeName' => 'attributeValue'));

+0

Haben Sie ein Beispiel, das eine Gruppe von Radiobuttons mit dem Modell Vereinigung erzeugt? Können Sie ein Beispiel erstellen, das den von mir geposteten HTML-Code generiert? – BadHorsie

0

Try this:

$options = array('1' => 'Test 1'); <br> $attributes = 
array('value'=>'1','class'=>'custom-class-1','id'=>'custom-id-1','data-something'=>'test1'); 

echo $this->Form->radio('field_name1', $options, $attributes); 

--------------------- 


$options = array('1' => 'Test 2'); <br> $attributes = 
array('value'=>'1','class'=>'custom-class-2','id'=>'custom-id-2','data-something'=>'test2'); 

echo $this->Form->radio('field_name2', $options, $attributes); 
Verwandte Themen