Creating an HTML radio element generator
A radio button element generator will share similarities with the generic HTML form element generator. As with any generic element, a set of radio buttons needs the ability to display an overall label and errors. There are two major differences, however:
Typically, you will want two or more radio buttons
Each button needs to have its own label
How to do it...
First of all, create a new
Application\Form\Element\Radio
class that extendsApplication\Form\Generic
:namespace Application\Form\Element; use Application\Form\Generic; class Radio extends Generic { // code }
Next, we define class constants and properties that pertain to the special needs of a set of radio buttons.
In this illustration, we will need a
spacer
, which will be placed between the radio button and its label. We also need to decide whether to place the radio button label before or after the actual button, thus, we use the$after
flag. If we need a default, or if we are re-displaying existing...