I've been following the guide here https://docs.moodle.org/dev/Form_API and this post https://moodle.org/mod/forum/discuss.php?d=126935 to create a form and learn to develop in Moodle. It's basically a bunch of radio buttons inside a table.
I've been using $radioarray[] = $mform->createElement('radio', ...) to create the radio buttons and $mform->addElement('html', ...) to create the html to wrap around the radio buttons.
The problem is that the html is being run first and then all the radio buttons are being created. This makes the table appear at the top and the radio buttons down below the table instead of inside it.
I posted my code below but omitted a lot of it because there is a lot of repetition.
$mform->addElement('html', '<table class="table table-condensed ">'
. '<colgroup>
<col>
...
...
...
$radioarray=array();
$mform->addElement('html', '<td>');
$radioarray[] = $mform->createElement('radio', 'grade', '', '', 80, array('class'=>'commenttextarea'));
$mform->addElement('html', '</td>'
. '<td class="text-center">');
...
...
...
$radioarray[] = $mform->createElement('radio', 'grade', '', '', 95, $attributes);
$mform->addElement('html', '</td>'
. '<td class="text-center">');
$radioarray[] = $mform->createElement('radio', 'grade', '', '', 100, $attributes);
$mform->addElement('html', '</td>'
. '</tr>'
. '</table>');
$mform->addGroup($radioarray, 'radioar', '', array(' '), false);
$this->add_action_buttons();