title: PHP adding elements in foreach loop not submitting
body: <p>I am making a form from database fields, so I pull all the records and loop through and add the form elements in a foreach loop in php. The problem is when I submit the form the elements are not posted, the only return I get is the submit button: - </p>
  
  <pre><code>stdClass Object
  (
      [submitbutton] =&gt; Submit
  )
  </code></pre>
  
  <p>This is how I create the elements, these all display and fucntion correctly onscreen, it just does not post when I submit, but the elements do post if I don't have them in the foreach loop, but I need to create them dynamically from the database, any ideas?</p>
  
  <pre><code>foreach($records as $log){
      $inc++;
  
      if($log-&gt;type == 0){ 
  
          $mform-&gt;addElement('html', '&lt;p&gt;'.$log-&gt;leadin.'&lt;/p&gt;');
  
          $attributes = array();
          $distractors = explode(',', $log-&gt;distractors);
          $radioarray=array();
          $count = 0;
  
          foreach($distractors as $dis){
              $count++;
              $radioarray[] =&amp; $mform-&gt;createElement('radio', 'radio', '', $dis, $count, array());
          }
  
          $mform-&gt;addGroup($radioarray, 'radioar'.$inc, '', array(' '), false);
      }
      else if($log-&gt;type == 1){
  
          $mform-&gt;addElement('html', '&lt;div&gt;'.$log-&gt;leadin.'&lt;/div&gt;');
  
          $distractors = explode(',', $log-&gt;distractors);
          $count = 0;
  
          foreach($distractors as $dis){
              $count++;
              $mform-&gt;addElement('checkbox', 'check'.$count, $dis);
          }
      }}
  </code></pre>
  
  <p>Here is an image of the output of the above code, all displays and functions correctly.</p>
  
  <p><img src="https://i.stack.imgur.com/nuKj7.jpg" alt="enter image description here"></p>
  
  <pre><code>&lt;form autocomplete="off" action="blocks/training_plan/student/survey.php" method="post" accept-charset="utf-8" id="mform1" class="mform"&gt;
  &lt;div style="display: none;"&gt;&lt;input name="sesskey" type="hidden" value="MJS9xXm2SA" /&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>Survey Choice 1?</p>
  
  <pre><code>&lt;fieldset class="hidden"&gt;&lt;div&gt;
      &lt;div id="fgroup_id_radioar1" class="fitem fitem_fgroup femptylabel"&gt;&lt;div class="fitemtitle"&gt;&lt;div class="fgrouplabel"&gt;&lt;label&gt; &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;fieldset class="felement fgroup"&gt;&lt;span&gt;&lt;input name="radio" value="1" type="radio" id="id_radio_1" /&gt;&lt;label for="id_radio_1"&gt;1&lt;/label&gt;&lt;/span&gt; &lt;span&gt;&lt;input name="radio" value="2" type="radio" id="id_radio_2" /&gt;&lt;label for="id_radio_2"&gt;2&lt;/label&gt;&lt;/span&gt; &lt;span&gt;&lt;input name="radio" value="3" type="radio" id="id_radio_3" /&gt;&lt;label for="id_radio_3"&gt;3&lt;/label&gt;&lt;/span&gt; &lt;span&gt;&lt;input name="radio" value="4" type="radio" id="id_radio_4" /&gt;&lt;label for="id_radio_4"&gt;4&lt;/label&gt;&lt;/span&gt;&lt;/fieldset&gt;&lt;/div&gt;&lt;div&gt;Survey choice 2?&lt;/div&gt;
      &lt;div id="fitem_id_check1" class="fitem fitem_fcheckbox "&gt;&lt;div class="fitemtitle"&gt;&lt;label for="id_check1"&gt;1 &lt;/label&gt;&lt;/div&gt;&lt;div class="felement fcheckbox"&gt;&lt;span&gt;&lt;input name="check1" type="checkbox" value="1" id="id_check1" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
      &lt;div id="fitem_id_check2" class="fitem fitem_fcheckbox "&gt;&lt;div class="fitemtitle"&gt;&lt;label for="id_check2"&gt;2 &lt;/label&gt;&lt;/div&gt;&lt;div class="felement fcheckbox"&gt;&lt;span&gt;&lt;input name="check2" type="checkbox" value="1" id="id_check2" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
      &lt;div id="fitem_id_check3" class="fitem fitem_fcheckbox "&gt;&lt;div class="fitemtitle"&gt;&lt;label for="id_check3"&gt;3 &lt;/label&gt;&lt;/div&gt;&lt;div class="felement fcheckbox"&gt;&lt;span&gt;&lt;input name="check3" type="checkbox" value="1" id="id_check3" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
      &lt;div id="fitem_id_check4" class="fitem fitem_fcheckbox "&gt;&lt;div class="fitemtitle"&gt;&lt;label for="id_check4"&gt;4 &lt;/label&gt;&lt;/div&gt;&lt;div class="felement fcheckbox"&gt;&lt;span&gt;&lt;input name="check4" type="checkbox" value="1" id="id_check4" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;
      &lt;div id="fitem_id_answer3" class="fitem fitem_ftextarea "&gt;&lt;div class="fitemtitle"&gt;&lt;label for="id_answer3"&gt;Survey choice 3? &lt;/label&gt;&lt;/div&gt;&lt;div class="felement ftextarea"&gt;&lt;textarea rows="10" cols="80" name="answer3" id="id_answer3"&gt;&lt;/textarea&gt;&lt;/div&gt;&lt;/div&gt;
      &lt;/div&gt;&lt;/fieldset&gt;
  &lt;fieldset class="hidden"&gt;&lt;div&gt;
      &lt;div id="fgroup_id_buttonar" class="fitem fitem_actionbuttons fitem_fgroup"&gt;&lt;div class="felement fgroup"&gt;&lt;input name="submitbutton" value="Submit" type="submit" id="id_submitbutton" /&gt; &lt;input name="cancel" value="Cancel" type="submit" onclick="skipClientValidation = true; return true;" class=" btn-cancel" id="id_cancel" /&gt;&lt;/div&gt;&lt;/div&gt;
      &lt;/div&gt;&lt;/fieldset&gt;
  </code></pre>
  
  <p></p>