0
我有一個基於在該狀態表還我有chekboxes所選項目的狀態下拉(名單在Drupal 7)。當我從下拉列表中選擇任何狀態時,所選狀態下的城市都希望顯示爲複選框。我的代碼是得到複選框在drupal7
function signup_form($form, &$form_state) {
$form['rate_the_service']['state'] = array(
'#type' => 'select',
//'#title' => 'State/Province',
'#prefix'=>'<div id="dropdown-third-replace">',
'#suffix'=>'</div>',
'#options'=>$opt,
'#attributes'=>array('selected'=>array('selected')),
'#validated' => TRUE,
'#ajax' => array(
'callback' => 'ajax_example_dependent_dcheck_state_callback',
'wrapper' => 'dropdown-four-replace',
),
);
$form['rate_the_service']['city'] = array(
'#prefix'=>'<div id="dropdown-four-replace">',
'#type' => 'checkboxes',
'#options' => '',
'#default_value' => isset($values['states']) ? $values['states'] : NULL,
'#suffix'=>'</div></div>',
);
}
Ajax調用
function ajax_example_dependent_dcheck_state_callback($form, $form_state) {
$state = $form_state['values']['state'];
$state_query_result2 = db_query('SELECT cityname FROM cities WHERE varstatekey = :varstatekey', array(':varstatekey' => $state));
$state_array = array();
// $state_array[0] = '-- Select State --';
foreach($state_query_result2 as $row2){
$state_array[$row2->cityname] = $row2->cityname;
}
$options[$state] = $state_array;
$form['rate_the_service']['city']['#options'] = $state_array;
//print_r($form['rate_the_service']['city']['#options']);
return $form['rate_the_service']['city'];
}
如何來解決這個問題。