Dynamic Field Adition / Subtraction using FAPI Goal Provide a user with a drop down menu defaulted to a value of none. Other options are the number 1 through 27. Based on the value select have drupal FAPI generate a fieldset that has anywhere from 1 to 27 required text fields. And should they then change their mind it would re-render accordingly.

What I have
So far I am able to get the FAPI to hide the field on initial form render however I can't seem to figure out how I'd take the selected array value and use that to generate out a new field set dynamically.

function single_add_ucm_form($form, &amp;$form_state) {
$form['number_subscribers'] = array(
'#type' =&gt; 'select',
'#title' =&gt; t('How many subscribers are in the CUCM cluster?'),
'#required' =&gt; TRUE,
'#default_value' =&gt;  0,
'#ajax' =&gt; array(
  'callback' =&gt; 'ajax_select_callback',
  'wrapper' =&gt; 'replace_subscribers_div',
  'effect' =&gt; 'slide',
 ),
'#options' =&gt; array(
  0 =&gt; t('none'),
  1 =&gt; t('1'),
  2 =&gt; t('2'),
  3 =&gt; t('3'),
  4 =&gt; t('4'),
  5 =&gt; t('5'),
  6 =&gt; t('6'),
  7 =&gt; t('7'),
  8 =&gt; t('8'),
  9 =&gt; t('9'),
  10 =&gt; t('10'),
  11 =&gt; t('11'),
  12 =&gt; t('12'),
  13 =&gt; t('13'),
  14 =&gt; t('14'),
  15 =&gt; t('15'),
  16 =&gt; t('16'),
  17 =&gt; t('17'),
  18 =&gt; t('18'),
  19 =&gt; t('19'),
  20 =&gt; t('20'),
  21 =&gt; t('21'),
  22 =&gt; t('22'),
  23 =&gt; t('23'),
  24 =&gt; t('24'),
  25 =&gt; t('25'),
  27 =&gt; t('26'),
  27 =&gt; t('27'),
),
);
$form ['subscribers_wrapper_container'] = array(
'#type' =&gt; 'container',
'#prefix' =&gt; '&lt;div id="replace_subscribers_div"&gt;',
'#suffix' =&gt; '&lt;/div&gt;',
);

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


function ajax_select_callback($form, $form_state) {
return $form['subscribers_wrapper_container'];
  }
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'][]['UCM_SUB'] = array(
    '#type' =&gt; 'textfield',
    '#size' =&gt; 30,
    '#title' =&gt; t('Subscriber IP Address'),
    '#required' =&gt; TRUE,
  );
}


You should add '#tree' =&gt; TRUE on your form, it will be easier to extract the form values afterwards