drupal菜单回调 - confirm提示框
drupal中自定义编写一些模块的时候 , 针对某一条记录或某一批数据进行操作时,有时需要确认窗口(confirm) , 该窗口包含一个确认按钮和一个取消按钮 . 下面是一个对删除功能操作,当点击delete时,会弹出一个确认删除的窗口("您确定要删除此项目吗?") , 点击确认表示执行此操作 . 反之 , 取消将不执行 .
function category_menu(){
$items['category/%/delete'] = array(
'title' => 'Category Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('category_delete_confirm', 1),
'access callback' =>TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function category_delete_confirm() {
$category_id =arg(1);
$form['category_id'] = array(
'#type' => 'value',
'#value' => $category_id,
);
return confirm_form($form,
t('Are you sure to delete this item?'),
isset($_GET['destination']) ? $_GET['destination'] : 'category_page',
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
function category_delete_confirm_submit($form, &$form_state){
if ($form_state['values']['confirm']) {
if($form_state['values']['category_id']){
db_query("DELETE FROM {evaluation_category} WHERE category_id = %d", $form_state['values']['category_id']);
$path .= 'evaluation_category_date_page';
}
drupal_set_message(t('Delete Successfully!'));
}
$form_state['redirect'] = $path;
}
- 添加新评论
- 423 次点击