[Solved] How to store Ajax Return value into variable after clicking the Submit button

balakrishnan Asks: How to store Ajax Return value into variable after clicking the Submit button
I have created form with fields of State and City. After selecting the state appropriate city records will be loaded into city field till now working fine but after clicking the submit button I am not able to store city value into variable called $data1. Please guide me how to get it city value

Code:
function form_test_form($form,&$form_submit) 
{
$form['state1']= array(
  '#type' => 'select',
  '#title' => t('State'),
  '#options' =>$options_state,
  '#required' => TRUE,
  '#ajax' => array(
    'callback' => '_ajaxfunction',
    'wrapper' => 'divaroundseconddropdown'
  ),
);

$form['city_element_wrapper'] = array(
    '#prefix' => '<div id="divaroundseconddropdown">',
    '#suffix' => '</div>',
  );

}

Ajax Function

Code:
 function _ajaxfunction($form, $form_state) 

    { 

$key = !empty($form_state['values']['state1']) ? $form_state['values']['state1'] : 1;

  $query_city=db_select('city', 'c');
  $query_city->fields('c',array('District_Code','District_Name','State_Code'));
  $query_city->condition('State_Code', $key, '=');

  $query_city->orderBy('District_Name','ASC');
  $city_results = $query_city->execute();
  $options_city = array();


  foreach ($city_results as $city_record)
{
    // This is correct.
    $options_city[$city_record->District_Code]=t($city_record->District_Name);
}

    $form['city_element_wrapper']['city']= array(
        '#type' => 'select',
        '#title' => t('District'),
        '#options' => $options_city,
        '#required' => TRUE,);

    return $form['city_element_wrapper']; 
    }

Now I am trying to store the value of what I have selected in City into $data1 variable but I am not able to store it, Please guide me how to store

Code:
function form_test_custom_form_submit($form, $form_state){
    $data1 = $form_state['values']['city_element_wrapper']['city'];
}

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.