An AJAX callback is not a submission callback; the submission callback is the usual one a form uses, independently from the form using AJAX or not.
An AJAX callback is given the $form
and $form_state
parameters, allowing it to produce a result, which it returns for rendering. Since it gets $form
as parameter, accessing that value simply means parsing $form['id']['mypreview_modal']['#markup']
.
function myid_user_page_form_ajax_submit($form, $form_state) {
// Parse $form['id']['mypreview_modal']['#markup'].
}
Keep in mind that usually an AJAX callback just returns the part of the form that needs to be rendered. See poll_choice_js()
as example.
function poll_choice_js($form, $form_state) {
return $form ['choice_wrapper']['choice'];
}
The rest is done from the submission handler. (In the case of the Poll module, and for the form using the previous AJAX callback, this is poll_more_choices_submit()
.)
// If this is a Ajax POST, add 1, otherwise add 5 more choices to the form.
if ($form_state ['values']['poll_more']) {
$n = $_GET ['q'] == 'system/ajax' ? 1 : 5;
$form_state ['choice_count'] = count($form_state ['values']['choice']) + $n;
}
// Renumber the choices. This invalidates the corresponding key/value
// associations in $form_state['input'], so clear that out. This requires
// poll_form() to rebuild the choices with the values in
// $form_state['node']->choice, which it does.
$form_state ['node']->choice = array_values($form_state ['values']['choice']);
unset($form_state ['input']['choice']);
$form_state ['rebuild'] = TRUE;