How can I render form elements? In Drupal 6, I am using the following code.
$rows[] = array(
  array('data' =&gt; drupal_render($form['collected'])),
  array(
    'data'=&gt; drupal_render($form['count']) . drupal_render($form['submit']),
    'colspan' =&gt; 3
  )
);

In Drupal 8, I am trying to use the following code, but I see the HTML markup of $form['count'].
$rows[] = [
  ['data' =&gt; \Drupal::service('renderer')-&gt;render(($form['collected'])],
  [
    'data' =&gt; \Drupal::service('renderer')-&gt;render($form['count']) . \Drupal::service('renderer')-&gt;render($form['submit']),
    'colspan' =&gt; 3,
  ]
];
In Drupal 8+, you do not need to use a separate theming function as was required in Drupal 6. You can put the form element directly into the table without rendering, and Drupal will handle that on the back-end. It's much simpler:
$row = [];
$row[] = [
  'data' =&gt; [
    'something' =&gt; $form['something'],
    'something_else' =&gt; $form['something_else'],
  ],
];

$rows[] = $row;