-
Notifications
You must be signed in to change notification settings - Fork 5
Select and Radio Checkbox groups
Steve "Uru" West edited this page Jul 31, 2013
·
5 revisions
Selects can be created simply by creating a new instance of a Select
and adding Option
s and/or Optgroup
s to it.
<?php
//Create the select element
$select = new Select();
//Add some regular options
$select[] = new Option('red');
$select[] = new Option('green');
$select[] = new Option('black');
//Create a new optgroup
$optGroup1 = new Optgroup();
//And add some options to it
$optGroup1[] = new Option('one');
$optGroup1[] = new Option('two');
$optGroup1[] = new Option('three');
//Add the group to the select
$select[] = $optGroup1;
The constructed Select
can then be added to a form as normal.
Radio buttons can be grouped by first adding them to a RadioGroup
.
Note that the name of the group is set after adding the Radio
s to the group. Setting the name of the group after assigning children will update all the contained Radio
s with the same name.
<?php
use Fuel\Fieldset\Input\RadioGroup;
use Fuel\Fieldset\Input\Radio;
$form = new Fuel\Fieldset\Form;
$group = new RadioGroup();
$group[] = new Radio('', array(), '1');
$group[] = new Radio('', array(), '0');
$group->setName('test');
$form[] = $group;
These work much the same way as the RadioGroup
s except that the name defaults to an array. Setting a group name of foo
will result in an input name of foo[]
. This behaviour can be configured using the setAutoArray
method from ToggleGroup
s.
<?php
use Fuel\Fieldset\Input\CheckboxGroup;
use Fuel\Fieldset\Input\Checkbox;
$form = new Fuel\Fieldset\Form;
$group = new CheckboxGroup();
$group[] = new Checkbox('', array(), '1');
$group[] = new Checkbox('', array(), '0');
$group->setName('test');
$form[] = $group;