Skip to content

Select and Radio Checkbox groups

stevewest edited this page Feb 11, 2013 · 5 revisions

Selects

Selects can be created simply by creating a new instance of a Select and adding Options and/or Optgroups to it.

<?php

//Create the select element
$select = new Select();

//Add some regular options
$select[] = new Option()->setContent('red');
$select[] = new Option()->setContent('green');
$select[] = new Option()->setContent('black');

//Create a new optgroup
$optGroup1 = new Optgroup();

//And add some options to it
$optGroup1[] = new Option()->setContent('one');
$optGroup1[] = new Option()->setContent('two');
$optGroup1[] = new Option()->setContent('three');

//Add the group to the select
$select[] = $optGroup1;

The constructed Select can then be added to a form as normal.

Radio/Checkbox groups

To do

Clone this wiki locally