Why is my form themed as table not posting data correctly, or displaying correctly? I have created a form in the admin.

$form['things'] = array(
  '#prefix' =&gt; '&lt;div id="things"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  '#tree' =&gt; TRUE,
  '#theme' =&gt; 'table',
  '#header' =&gt; array(t('Field Label'), t('Field Name'), t('Location'), t('Stuff')),
  '#rows' =&gt; array(),
);


I then add each row to it like:

foreach ($type_fields as $field_name =&gt; $attrs) {
  $stuff = array(
    '#type' =&gt; 'textfield',
    '#default_value' =&gt; $attrs['stuff'],
  );

$form['things']['#rows'][] = array(
  array('data' =&gt; 'label'),
  array('data' =&gt; $field_name),
  array('data' =&gt; $field_name),
  array('data' =&gt; $stuff),
);


}

The form looks great! But the first problem is the value assigned to #default_value is not showing up in the form.  When I change it to #value the correct value DOES show up. So I wonder how this should be done? The Drupal documentation says #value should not be used with forms although it is functioning exactly how I would expect it to function.

The main problem is when I fill in some test data in one of the textfields and submit it: I do not see any of the submitted values in my _submit function.

Neither $form nor $form_state contains any of the values I input into the text fields.

I wonder if this is because I am rendering #theme =&gt; "table"?  Has any one ran into this issue? Any Ideas on changes I can make that would allow me to see the values I am inputting when I post the form to the _submit function?
The problem is that your textfield elements are located under the #rows property of your render array.

Drupal sees any array key beginning with # as a property/attribute, and any array key not beginning with that as an element that needs to be recursively attended to. As such the children you've got under #rows will be ignored by the form builder.

Since theme_table will run on the render array, your form elements will actually be rendered out to the screen, but the form won't have any knowledge of the values (as they are not technically children of the form).

In my experience the best way to do this sort of thing is to use a specific theme function on the element:

function MYMODULE_theme() {
  return array(
    'MYMODULE_textfield_table' =&gt; array(
      'render element' =&gt; 'element'
    )
  );
}

function theme_MYMODULE_textfield_table($vars) {
  $element = $vars['element'];

  $rows = array();
  foreach (element_children($element) as $key) {
    $rows[] = array(
      array('data' =&gt; 'label'),
      array('data' =&gt; $element[$key]['#extra_data']['field_name']),
      array('data' =&gt; $element[$key]['#extra_data']['field_name']),
      array('data' =&gt; render($element[$key]))
    );
  }

  $header = array(t('Field Label'), t('Field Name'), t('Location'), t('Stuff'));
  return theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows));
}


Then in your form function you would use code like the following

$form['things'] = array(
  '#prefix' =&gt; '&lt;div id="things"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  '#tree' =&gt; TRUE,
  '#theme' =&gt; 'MYMODULE_textfield_table'
);

foreach ($type_fields as $field_name =&gt; $attrs) {
  $form['things'][] = array(
    '#type' =&gt; 'textfield',
    '#default_value' =&gt; $attrs['stuff'],
    '#extra_data' =&gt; array('field_name' =&gt; $field_name)
  );
}


After that your textfields should be registered in the form and you should be able to see the value in the $form_state array as normal.