Missing values in $form_state[‘values’] when addding field through _form_alter after AJAX callback

I want to add a couple of fields to a content type form using AJAX and, upon validation, run a custom _submit callback to do something with those fields.

My approach:

1. Alter the form adding a select that triggers the ajax, evaluates the value of $ form_state[‘values’][and produces two textfield fields:

function hook_form_FORM_ID_alter(&$  form, &$  form_state, $  form_id) {   $  form['info'] = array(     '#type' => 'fieldset',     '#title' => t('Information'),,     '#prefix' => '<div id="ajax-info">',     '#suffix' => '</div>',   );    if ($  form_state['values']['some_value'] == 'some_other_value') {     $  form['info']['input_1'] = array(       '#type' => 'textfield',       '#title' => t('Input 1'),     );      $  form['info']['input_2'] = array(       '#type' => 'textfield',       '#title' => t('Input 2'),     );   }    // some validation   $  form['#validate'][] = 'my_module_FORM_ID_form_validate';    // append it to the bottom because it's important that it is executed after the default submit callback   $  form['actions']['submit']['#submit'][] ='my_module_FORM_ID_form_submit'; } 

2. Return the relevant part of code in the ajax callback:

function my_ajax_callback($  form, $  form_state){   return $  form['info']; } 

My problem comes when implementing my_module_FORM_ID_form_submit, as it seems that $ form_state[‘input_1’] and $ form_state[‘input_2’] are not set.

Sometimes, after clearing cash, input_1 and input_2 may be read in the callback and everything may work. But eventually, errors occur after a few attempts.

I also tried setting $ form_state['rebuild'] = TRUE in the _validation without success.

Can it be a problem with the way I’m adding the submit callback? I cannot add it to $ form[‘#submit][] because the default form callback is not defined there and it’s important that my custom callback gets executed last.