I can't render default values on form element in theme_table() For the last few days and some of last week I've been trying to fix up the interface of a page we have on one of our modules since it was difficult to use. I decided to take this data and just display it in a table so that it's simple and organized by column.

Here is a very basic recreation of the code.

function _ss_menu_zone_test($form, $form_state) {

  $formfield = array(
    '#type' =&gt; 'textfield',
    '#default_value' =&gt; '10' // default value set
  );
  $formselect = array(
    '#type' =&gt; 'select',
    '#options' =&gt; array(1,2,3,4,5,6),
    '#default_value' =&gt; 3  // default value set
  );

  $tablesort_headers =array(
    array('data' =&gt; t('Price'), 'field' =&gt; 'price'),
  );

  $tablesort_rows = array(
    array('price' =&gt; 'test row format 1'), // example of basic string row
    array('price' =&gt; array('data' =&gt; 'test row format 2')), // example of simple string but using data
    array('price' =&gt; drupal_render($formfield)),
    array('price' =&gt; array('data' =&gt; $formfield)),
    array('price' =&gt; drupal_render($formselect)),
  );

  // render the tablesort of menu items.
  $form['category_' . $tid]['items'] = array(
    '#theme' =&gt; 'table',
    '#header' =&gt; $tablesort_headers,
    '#rows' =&gt; $tablesort_rows,
    '#sticky' =&gt; TRUE,
    '#attributes' =&gt; array('id' =&gt; 'zone-items-' . $tid)
  );

  return $form;
}


In this example I have one column for the test data and a couple rows to show the differences. The primary issue I've run into here is if I try to add a form API textfield to a cell somewhere it drops value for the #default_value. the field renders correctly with any other key I've specified.

Does anyone know how to go about getting this #default_value to actually populate the field like it does EVERYWHERE else in the Form API?
In FAPI (and renderable arrays in general), keys starting with a # are considered properties - so not renderable elements. This means their children aren't processed for content properly.

There are several methods to do what you want, but the easiest is probably references. In your specific example, it would look like this (I've trimmed out some stuff to make my changes more clear):

function _ss_menu_zone_test($form, &amp;$form_state) {

  $tablesort_headers =array(
    array('data' =&gt; t('Price'), 'field' =&gt; 'price'),
  );

  // render the tablesort of menu items.
  $form['category_' . $tid]['items'] = array(
    '#theme' =&gt; 'table',
    '#header' =&gt; $tablesort_headers,
    '#rows' =&gt; array(),
    '#sticky' =&gt; TRUE,
    '#attributes' =&gt; array('id' =&gt; 'zone-items-' . $tid)
  );

  $formfield = array(
    '#type' =&gt; 'textfield',
    '#default_value' =&gt; '10' // default value set
  );

  //We need to include the field in the form so it's rendered. This wont display because we're using #theme =&gt; table.
  $form['category_' . $tid]['items'][] = array('formfield' =&gt; &amp;$formfield);

  //These are your rows, note the byreference on the formfield.
  $tablesort_rows = array(
    array('price' =&gt; 'test row format 1'), // example of basic string row
    array('price' =&gt; array('data' =&gt; 'test row format 2')), // example of simple string but using data
    array('price' =&gt; array('data' =&gt; &amp;$formfield)),
  );

  //Add your rows to the table.
  $form['category_' . $tid]['items']['#rows'] = $tablesort_rows;

  //Since we used references we want to unset the variables we created.
  unset($formfield);

  return $form;
}