I tried to mimic the multiple user deletion feature of user.module but for some reason the confirm form submit handler never get called. I don't know where the problem lies in. Following is a working sample of module except for the function delete_multiple_server_confirm_form_submit which never gets executed.
function mymodule_menu() {
$items['testservers'] = array(
'title' => 'Manage Servers',
'page callback' => 'display_servers_callback',
'page arguments' => array('delete'),
'access callback' => true,
);
return $items;
}
function display_servers_callback($args = '') {
$op = isset($_POST['op']) ? $_POST['op'] : $args;
$op = strtolower($op);
$build_form = array();
if (!empty($_POST['table']) && isset($_POST['operation']) && ($_POST['operation'] == 'delete')) {
$options = $_POST['table'];
$build_form['delete_multiple_server_confirm_form'] = drupal_get_form('delete_multiple_server_confirm_form', $options);
}
else {
$build_form['display_servers_form'] = drupal_get_form('display_servers_form');
}
return $build_form;
}
function delete_multiple_server_confirm_form($form, &$form_state, $servers) {
$path = current_path();
return confirm_form($form, t('Are you sure you want to delete %title?'), $path, t('This action cannot be undone.'), t('Delete'), t('Cancel')
);
}
function display_servers_form($form, $form_state) {
$header = array(
'server_name' => array('data' => t('Server Name')),
'location' => array('data' => t('Location')),
'protocols' => array('data' => t('Protocols')),
'status' => array('data' => t('server status ')),
);
$servers = array(
array('server_name' => 'us1', 'location' => 'us', 'protocols' => 'test', 'status' => 'ok'),
array('server_name' => 'us2', 'location' => 'us', 'protocols' => 'test', 'status' => 'ok'),
array('server_name' => 'us3', 'location' => 'us', 'protocols' => 'test', 'status' => 'ok'),
);
$options = array();
for ($index = 0; $index < count($servers); $index++) {
$options[$index] = array(
'server_name' => $servers[$index]['server_name'],
'location' => $servers[$index]['location'],
'protocols' => $servers[$index]['protocols'],
'status' => $servers[$index]['status'],
);
}
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No servers found'),
);
$options = array();
$operations = array('delete' => array(
'label' => t('delete servers'),
'callback' => 'delete_multiples',
),
'suspend' => array(
'label' => t('suspend servers'),
),
);
foreach ($operations as $operation => $array) {
$options[$operation] = $array['label'];
}
$form['options']['operation'] = array(
'#type' => 'select',
'#title' => t('Operation'),
'#title_display' => 'invisible',
'#options' => $options,
'#default_value' => 'delete',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
);
return $form;
}
function delete_multiple_server_confirm_form_submit($form, &$form_state, $servers) {
drupal_set_message('working');
}