Answer the question
In order to leave comments, you need to log in
Drupal 7. How to change select subgroup using ajax?
Good afternoon.
Question to respected Drupal 7 experts. I create a form through the Form API, I attach the code:
function sendMailChiefs_form($form, &$form_state) {
$AllGroups = array(
'4601' => 'TopCheif',
);
$keyAssocArr = key($AllGroups);
$query = db_select('drupal.users', 'u');
$query->fields('u', array('Nceh', 'FIO', 'mail'));
$query->condition('u.Nceh', $keyAssocArr, '=');
$result = $query->execute();
$topChiefFIOFIO = [];
$topChiefMail = [];
$topChiefAll = [];
$topChiefNumb = [];
foreach ($result as $row) {
$topChiefFIO[] = $row->FIO;
$topChiefMail[] = $row->mail;
$topChiefNumb[] = $row->Nceh;
$topChiefAll = array_combine($topChiefMail, $topChiefFIO);
}
// print_r($topChiefAll);
$selected_top_chief = $form_state['values']['select_group'] == '4601' ? $topChiefAll : $form_state['values']['select_group'];
$form = array();
$form['select_group'] = array(
'#type' => 'select',
'#title' => 'Выберете групу пользователей:',
'#options' => $AllGroups,
'#description' => 'Выберите групу',
'#empty_option' => '--Выберите групу--',
'#required' => true,
'#ajax' => array(
'wrapper' => 'main-chief',
'callback' => 'sendMailChiefs_callback',
),
);
print_r($selected_top_chief);
$form['select_top_chief'] = array(
'#type' => 'select',
'#title' => 'Вопрос к членам правления',
'#options' => $selected_top_chief,
'#description' => 'Выберите одного из членов правления',
'#required' => true,
'#ajax' => array(
'wrapper' => 'landing-cities',
'callback' => 'sendMailChiefs_callback',
),
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => 'Отправить',
);
print_r($form_state['values']);
return $form;
}
function sendMailChiefs_callback($form, $form_state) {
return $form['select_group'];
}
Answer the question
In order to leave comments, you need to log in
Thanks, it turned out that print_r had a bad effect on code behavior :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question