我有一个在ctools ajax drupal 7中打开的表单。在该表单的保存按钮上,它应该保存数据并关闭弹出窗口,然后打开一个新的弹出窗口。 通过链接打开时,此新弹出窗口将收到一个ID。我怎样才能做到这一点。 我是drupal 7的新手。
function save_and_open_popup2_callback($form, &$form_state)
ctools_include('modal');
ctools_modal_add_js();
$output=ctools_modal_form_wrapper('my_game_result_form',$form_state,$ID);
$commands = array();
$commands[] = ctools_modal_command_display('Title', $output);
print ajax_render($commands);
}
我无法在此弹出窗口中获取$ ID或form_state。
$game_link = l('<div>New Game</div>', 'game/nojs', array('attributes' => array('class' => 'ctools-use-modal'), 'html' => TRUE));
$game_result_link = l('<div>Game 1</div>', 'game_result/nojs/'.$ID, array('attributes' => array('class' => 'ctools-use-modal'), 'html' => TRUE));
function my_game_menu() {
$items = array();
$items['game/%ctools_js'] = array(
'page callback' => 'my_game_callback',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
$items['game_result/%ctools_js/%'] = array(
'page callback' => 'game_result_callback',
'page arguments' => array(1,2),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
}
function my_game_callback($ajax, $ID){
if ($ajax){
ctools_include('ajax');
ctools_include('modal');
$popup_title = "First popup";
$form_state = array(
'ajax' => TRUE,
'title' => $popup_title
);
$output = ctools_modal_form_wrapper('my_game_form', $form_state);
if (!empty($form_state['ajax_commands'])) {
$output = $form_state['ajax_commands'];
}
print ajax_render($output);
}else{
return drupal_get_form('my_game_form');
}
}
function my_game_form($form, $form_state) {
$form['game'] = array(
'#type' => 'submit',
'#value' => t('Save and Open'),
'#name' => 'game',
'#disabled' => false,
'#ajax' => array(
'callback' => 'save_and_open_popup2_callback'
),
);
}
function save_and_open_popup2_callback($form, &$form_state){
/** process of save data ...*/
/** Open another popup and close my_add_edit_form popup */
}
function game_result_callback($ajax, $ID){
/*** will open popup of game result thriugh call back same as in
"my_game_callback" ***/
$output = ctools_modal_form_wrapper('my_game_result_form', $form_state);
print ajax_render($output);
......
}
function my_game_result_form($form, $form_state){
/* form for my_game_result popup*/
}
根据代码,我有两个模态,它们在link上打开。现在,我还希望当我使用Ajax回调关闭“ my_game_form”时,打开第二个模式弹出窗口“ my_game_result_form”。第二个弹出窗口应该收到$ ID,这样我就可以基于$ ID获取数据。我应该在save_and_open_popup2_callback()里面写些什么,这完全可以满足我的要求。