Table in custom form + empty values in form_state In a custom form I created a table element:

  // Table results.
  $form['table'] = [
    '#type' =&gt; 'table',
    '#header' =&gt; $header,
    '#rows' =&gt; $rows,
    '#attributes' =&gt; ['id' =&gt; 'table-results'],
    '#empty' =&gt; t('No results.'),
    '#prefix' =&gt; '&lt;div id="ajax-table-results"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;'
  ];


This table is ajaxified and updated when I click on a specific button.

I need to get the output HTML of this table in another function. If I use a dpm($form_state->getValue('table')); I get an empty array. Yet, the other values (of other fields) are accessible in the $form_state.

// My second function
public function secondfunction(array $form, FormStateInterface $form_state) {
  dpm($form_state-&gt;getValue('table')); // -&gt; empty value...
  dpm($form_state-&gt;getValue('textfield')); // I get a value
}


What do I change in my code to solve this problem?
When you want to get the HTML of the table you must use the renderer service.

In Drupal 8:

$html = \Drupal::service('renderer')-&gt;render($form['table']);


Or better, use dependency injection :)

In Drupal 7:

$html = drupal_render($form['table']);