Cannot fetch form_state['values'] of text field from dynamically created Ajax fields I have a custom form with dynamically generated fields. I am unable to fetch values from these fields using form_state['values']. Code is attached below. I have been struggling with this since two days, but have not found anything that can fix the issue. Please help!!!

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


$form['#tree'] = TRUE;

$form['names_fieldset'] = array(
  '#type' =&gt; 'fieldset',
  '#title' =&gt; t('People coming to the picnic'),
  '#prefix' =&gt; '&lt;div id="names-fieldset-wrapper"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
);

if (empty($form_state['num_names'])) {
  $form_state['num_names'] = 1;
}
for ($i = 0; $i &lt; $form_state['num_names']; $i++) {
  $form['names_fieldset']['name'][$i] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Name'),
);
if(!empty($form_state['values'][$i]) &amp;&amp;  ($form_state['values'][$i] !='')) {
drupal_set_message($form_state['values'][$i]);//&lt;-- This statement never gets executed. Also cannot fetch the value of $form_state['values'][$i] 
}


}
 $form['names_fieldset']['add_name'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Add one more'),
  '#submit' =&gt; array('ajax_example_add_more_add_one'),
  '#ajax' =&gt; array(
  'callback' =&gt; 'ajax_example_add_more_callback',
  'wrapper' =&gt; 'names-fieldset-wrapper',
),
);
if ($form_state['num_names'] &gt; 1) {
  $form['names_fieldset']['remove_name'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Remove one'),
    '#submit' =&gt; array('ajax_example_add_more_remove_one'),
    '#ajax' =&gt; array(
      'callback' =&gt; 'ajax_example_add_more_callback',
      'wrapper' =&gt; 'names-fieldset-wrapper',
  ),
);
}
$form['submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Submit'),
);


return $form;
}

function ajax_example_add_more_add_one($form, &amp;$form_state) {
 $form_state['num_names']++;
 $form_state['rebuild'] = TRUE;
}

function ajax_example_add_more_callback($form, $form_state) {
 return $form['names_fieldset'];
}

function ajax_example_add_more_remove_one($form, &amp;$form_state) {
 if ($form_state['num_names'] &gt; 1) {
   $form_state['num_names']--;
 }
 $form_state['rebuild'] = TRUE;
}
You have used $form_state['num_names'] instead of $form_state['values']['num_names'].

Please try to update and see.