Ajax replaced elements not available in form submit callback I have some elements in a form as below:

$form['provider'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Provider'),
    '#required' =&gt; TRUE,   
    '#options' =&gt; $some_options,
    '#ajax' =&gt; array(
        'callback' =&gt; 'my_callback_func',
         'wrapper' =&gt; 'tests-div',
         'method' =&gt; 'replace',
         'effect' =&gt; 'fade',
     ),
);

$form['tests'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Tests'),
    '#required' =&gt; TRUE,
    '#prefix' =&gt; '&lt;div id="tests-div"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#options' =&gt; array(''),
    '#validated' =&gt; TRUE,
 );


When the provider select box value is changed, the callback my_callback_func checks the chosen value of the select box, and returns a modified version of tests select box with some new options set.

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

    [snipped code which reads form data and calculates $some_new_opts ] 

    $form['tests'] = array(
          '#type' =&gt; 'select',
          '#title' =&gt; t('Tests'),
          '#required' =&gt; TRUE,
          '#prefix' =&gt; '&lt;div id="tests-div"&gt;',
          '#suffix' =&gt; '&lt;/div&gt;',
          '#options' =&gt; $some_new_opts,
          '#validated' =&gt; TRUE,
    );

    return $form['tests'];
}


So far so good - when I change the value of the provider select I can see the Ajax event firing, the new options appear in the tests checkbox and I can select from them. But then when I submit the form using

$form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; 'go for it',
    '#submit' =&gt; array('my_post_submit_function'),
 );


none of the Ajax supplied values are visible in either form or form_state within my_post_submit_function. Instead, the original value (the empty array) is always shown in $form['tests']['#options'], and $form_state['values']['tests'] is null (""). 

What am I doing wrong ? 

Updated 4th Sept

I'm still trying to solve this problem. 
I've looked in a debugger at what happens when I click the submit button.

index.php and menu.inc direct control to form.inc, where drupal_get_form makes a call to drupal_build_form.

At this point $form_state seems to be being reconstructed from somewhere (the cache_form table?) as it certainly doesn't contain the settings I made to it during my earlier processing. (for e.g. I set $form_state['foo'] = "bar"; which has now disappeared.)

Does anybody know how this works in more detail? Does form caching mean that it's impossible to submit Ajax-modified data to the submit handler?
I received some help on Drupal.org about this... Jaypan's helpful reply is at https://www.drupal.org/node/2563045. I've posted a comment there to show how I got this working eventually.