Skip to content

forms multi input

Harmen Janssen edited this page Jun 30, 2015 · 2 revisions

Rendering a set of checkboxes

$form->addElement('multicheckbox', 'rappers', array(
	'label' => 'Pick your favorite rappers:',
	'multiOptions' => array(
		'md' => 'Mos Def',
		'tk' => 'Talib Kweli',
		'gu' => 'Guru',
		'mf' => 'MF DOOM'
	)
));

Rendering a set of radiobuttons

$form->addElement('radio', 'rappers', array(
	'label' => 'Pick your favorite rapper:',
	'multiOptions' => array(
		'md' => 'Mos Def',
		'tk' => 'Talib Kweli',
		'gu' => 'Guru',
		'mf' => 'MF DOOM'
	)
));

Setting attributes on the labels of multi input elements

For sets of radiobuttons or checkboxes, prefix any option in the array with "label_" to have it resolve to a label attribute:

$form->addElement('radio', 'rappers', array(
	'label' => 'Pick your favorite rapper:',
	'multiOptions' => array(
		'md' => 'Mos Def',
		'tk' => 'Talib Kweli',
		'gu' => 'Guru',
		'mf' => 'MF DOOM'
	),
	"label_class" => "radio-label"
));

This will make the labels look like this:

<label for="mf-field" class="radio-label"><input id="rappers-field-mf">MF DOOM</label>
```
Clone this wiki locally