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...

  1. First of all, create a new Application\Form\Element\Radio class that extends Application\Form\Generic:
    namespace Application\Form\Element;
    use Application\Form\Generic;
    class Radio extends Generic
    {
      // code
    }
    
  2. Next, we define class constants and properties that pertain to the special needs of a set of radio buttons.
  3. In this illustration, we will need a ...

Get PHP 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.