Generating an HTML single select element is similar to the process of generating radio buttons. The tags are structured differently, however, in that both a SELECT
tag and a series of OPTION
tags need to be generated.
First of all, create a new
Application\Form\Element\Select
class that extendsApplication\Form\Generic
.The reason why we extend
Generic
rather thanRadio
is because the structuring of the element is entirely different:namespace Application\Form\Element; use Application\Form\Generic; class Select extends Generic { // code }
The class constants and properties will only need to add slightly to
Application\Form\Generic
. Unlike radio buttons or checkboxes, there is no need to account for spacers or the placement of the selected text:const DEFAULT_OPTION_KEY = 0; const DEFAULT_OPTION_VALUE = 'Choose'; protected $options; protected $selectedKey = DEFAULT_OPTION_KEY;
Now we turn our attention to setting options. As an HTML...