The following code is displaying the states, but when I click the submission button, I want to display the selected state and city. I am not able to display it. How can I achieve this?
$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>',
);
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);
}
// Render city setting.
$form['city_element_wrapper']['city'] = array(
'#type' => 'select',
'#title' => t('District'),
'#options' => $options_city,
'#required' => TRUE,);
return $form['city_element_wrapper'];
}
The following code is not working properly:
function form_test_form_submit($form, $form_state) {
echo $prog_state = $form_state['values']['state1'];
echo $data1 = $form_state['values']['city_element_wrapper'];
}