Form elements as arrays #tree So I'm struggling with the concept of trees in Drupal. I have a form that presents a user with a drop down of number 1 - 27 depending on what they pick the form renders out an equal number of text fields. The goal is to collect all the values put into the text fields into an array even if it's a single element. Right now all that seems to happen is the last field is written as a string to the variable.

What I have:

if (!isset($form_state['values']['number_subscribers'])) {
$form_state['values']['number_subscribers'] = 0;
}

for($i = 0; $i &lt; $form_state['values']['number_subscribers']; $i++){
$form['subscribers_wrapper_container'][]["#tree"] = TRUE;
$form['subscribers_wrapper_container'][]['UCM_SUB'] = array(
'#type' =&gt; 'textfield',
'#size' =&gt; 30,
'#title' =&gt; t('Subscriber IP Address'),
'#required' =&gt; TRUE,
);
}


End goal would be to read $form_state['values']['UCM_SUB'] and have it return an array.
This:

$form['subscribers_wrapper_container'][]["#tree"] = TRUE;
$form['subscribers_wrapper_container'][]['UCM_SUB'] = array(...


Can't be what you meant to do. You're creating two new elements there, one with only #tree in it.

Surely you want the tree on the outer element, e.g.

$form['subscribers_wrapper_container']['UCM_SUB']['#tree'] = TRUE;

for($i = 0; $i &lt; $form_state['values']['number_subscribers']; $i++){
  $form['subscribers_wrapper_container']['UCM_SUB'][] = array(
    '#type' =&gt; 'textfield',
    '#size' =&gt; 30,
    '#title' =&gt; t('Subscriber IP Address'),
    '#required' =&gt; TRUE,
  );
}