title: ZF2 How to set <input type='radio' CHECKED> with a custom Form Element
body: <p>How do I set <strong>checked</strong> within a form input radio field?  This form field is added using a custom Form Element.  The value of this field isn't consistent.  </p>
  
  <p>My custom Form Element returns 1 element.  It is a radio input field.  I need this checked each and every time the form is submitted.  The reason I am using this instead of a "hidden" field is for the user to see this settings.  </p>
  
  <p>This is the custom Form Element</p>
  
  <pre><code>namespace Member\Form\Element;
  
  use Doctrine\ORM\EntityManager;
  use Zend\Form\Element\Radio;
  
  /**
  * Class OriginalLanguageIsoRadio
  *
  * @package Member\Form\Element
  */
  class OriginalLanguageIsoRadio extends Radio
  {
     /**
      * @var EntityManager $entityManager
      */
     protected $entityManager;
  
     /**
      * @var string $translationKey
      */
     protected $translationKey;
  
     /**
      * @var string $textDomain
      */
     protected $textDomain;
  
     /**
      * @param EntityManager $entityManager
      * @param string $translationKey
      * @param string $textDomain
      */
     public function __construct(
         EntityManager $entityManager,
         $translationKey,
         $textDomain
     )
     {
         $this-&gt;entityManager = $entityManager;
  
         $this-&gt;translationKey = $translationKey;
  
         $this-&gt;textDomain = $textDomain;
     }
  
     /**
      * Get Value Options
      *
      * @return array
      *
      * @throws \Exception
      */
     public function getValueOptions()
     {
         $array = [];
  
         $query = $this-&gt;entityManager
             -&gt;createQueryBuilder()
             -&gt;from(
                 'AMDatabase\Entity\TheVerse\TranslationsMasters',
                 't'
             )
             -&gt;select('t.languageIso')
             -&gt;setMaxResults(1);
  
         $result = $query-&gt;getQuery()
                         -&gt;getArrayResult();
  
         if (is_array($result) &amp;&amp; count($result) &gt; '0') {
             foreach ($result AS $value) {
                 if ( $value['languageIso'] == '' ) {
                     $array['Global'] = $value['Global'];
                 } else {
                     $array[$value['languageIso']] = $value['languageIso'];
                 }
             }
         }
  
         return $array;
     }
  </code></pre>
  
  <p>}</p>
  
  <p>Then I call the custom Form Element:</p>
  
  <pre><code>/**
   * Original Language Iso
   */
  $this-&gt;add(
      [
          'type'       =&gt; 'Member\Form\Element\OriginalLanguageIsoRadio',
          'name'       =&gt; 'original_language_iso',
          'options'    =&gt; [
              'label' =&gt; 'original_language_iso'
          ],
          'attributes' =&gt; [
              'id' =&gt; 'original_language_iso',
          ]
      ]
  );
  </code></pre>
  
  <p>This adds the following to my form:</p>
  
  <pre><code>&lt;input type="radio" name="original_language_iso" id="original_language_iso" value="en-US"&gt;
  </code></pre>
  
  <p>My desired output is</p>
  
  <pre><code>&lt;input type="radio" name="original_language_iso" id="original_language_iso" value="en-US" **checked**&gt;
  </code></pre>