Advertisement:

Author Topic: Need some help with adding remove checkboxes code  (Read 466 times)

Offline tareko

  • Semi-Newbie
  • *
  • Posts: 45
Need some help with adding remove checkboxes code
« on: September 15, 2020, 10:10:55 AM »
I have a mod coded for me by someone that lists the names of the games and their players in the acp. I am trying to add a checkbox list that will delete selected players but I can't seem to get it right. When I press delete selected players it does nothing at all. It just redirects to the players list page. Can someone please look at the code and tell me how can I implement it right?

Code: [Select]
function Players()
{
global $txt, $sourcedir, $scripturl, $context, $smcFunc;

isAllowedTo('admin_forum');

// User pressed the 'remove selection button'.
if (!empty($_POST['removePlayers']) && !empty($_POST['remove']) && is_array($_POST['remove']))
{
checkSession();

// Make sure every entry is a proper integer.
foreach ($_POST['remove'] as $index => $spider_id)
$_POST['remove'][(int) $index] = (int) $spider_id;

// Delete them all!
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_players
WHERE id_player IN ({array_int:remove_list})',
array(
'remove_list' => $_POST['remove'],
)
);
}

$listOptions = array(
'id' => 'player_list',
'items_per_page' => 20,
'base_href' => $scripturl . '?action=admin;area=players;sa=list',
'default_sort_col' => 'subject',
'no_items_label' => $txt['no_players_yet'],
'get_items' => array(
'function' => 'list_getPlayers',
),
'get_count' => array(
'function' => 'list_countPlayers',
),
'columns' => array(
'game' => array(
'header' => array(
'value' => $txt['players_list'],
),
'data' => array(
'db' => 'game',
'class' => 'mediumtext',
'style' => 'width: 40%; text-align: left;',
),
'sort' =>  array(
'default' => 'game DESC',
'reverse' => 'game',
),
),
'player_username' => array(
'header' => array(
'value' => $txt['players'],
'style' => 'text-align: left;',
),
'data' => array(
'db' => 'player_username',
'style' => 'width: 60%; text-align: left;',
),
'sort' =>  array(
'default' => 'player_username DESC',
'reverse' => 'player_username',
),
),

  'check' => array(
'header' => array(
'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
),
'data' => array(
'sprintf' => array(
'format' => '<input type="checkbox" name="remove[]" value="%1$d" class="input_check" />',
'params' => array(
'id_player' => false,
),
),
'style' => 'text-align: center',
),
),
),
'form' => array(
'href' => $scripturl . '?action=admin;area=players;sa=list',
),
'additional_rows' => array(
array(
'position' => 'below_table_data',
'value' => '
<input type="submit" name="removePlayers" value="' . $txt['remove_selected_players'] . '" onclick="return confirm(\'' . $txt['remove_selected_players_confirm'] . '\');" class="button_submit" />
',
'style' => 'text-align: right;',
),
),
);

require_once($sourcedir . '/Subs-List.php');
createList($listOptions);

$context['sub_template'] = 'show_list';
$context['default_list'] = 'player_list';
}

Offline SychO

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,900
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: Need some help with adding remove checkboxes code
« Reply #1 on: September 15, 2020, 10:26:56 AM »
try checking the contents of the posted data to make sure they are correct

past
Code: [Select]
var_dump($_POST['remove']);
die();

inside the condition block.
Take the initiative

Offline tareko

  • Semi-Newbie
  • *
  • Posts: 45
Re: Need some help with adding remove checkboxes code
« Reply #2 on: September 15, 2020, 11:50:20 AM »
try checking the contents of the posted data to make sure they are correct

past
Code: [Select]
var_dump($_POST['remove']);
die();

inside the condition block.

Thanks. I got this.

Code: [Select]
array(2) { [0]=> string(1) "0" [1]=> string(1) "0" }

What does it mean?

Offline SychO

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 1,900
  • Gender: Male
    • SychO9 on GitHub
    • SychO
Re: Need some help with adding remove checkboxes code
« Reply #3 on: September 15, 2020, 05:12:11 PM »
seems like the checkbox values aren't correctly set.

I don't remember the last time I used the createList function, so I'm not sure how that's supposed to work exactly.
Take the initiative


Offline tareko

  • Semi-Newbie
  • *
  • Posts: 45
Re: Need some help with adding remove checkboxes code
« Reply #5 on: September 16, 2020, 06:55:33 AM »
The OP contacted me and I fixed this for him.

Doug is the best.