Bestrafung
07-23-2014, 05:21 PM
I am trying to add checkboxes to the free agent signup form in the vbTournaments mod. I have created the extra field in the database table and a single selection works without issue. The problem I have is that when multiple checkboxes are selected only the last selection is saved to the database instead of all of the choices.
tmnt_newfreeagent template:
<form class="vbform block" action="teams.php?do=addfreeagent" method="post">
<div class="blockbody formcontrols">
<div class="blockrow">
<label for="game">Game</label>
<div style="overflow:auto">
<input type="checkbox" name="game[]" value="Aliens vs. Predator">Aliens vs. Predator<br />
<input type="checkbox" name="game[]" value="Chivalry: Medeival Warfare">Chivalry: Medeival Warfare<br />
<input type="checkbox" name="game[]" value="Counter-Strike: Global Offensive">Counter-Strike: Global Offensive<br />
<input type="checkbox" name="game[]" value="Insurgency">Insurgency<br />
</div>
<p class="description">Please select the game(s) you play.</p>
</div>
</div>
<div class="blockfoot actionbuttons">
<div class="group">
<input type="submit" class="button" value="{vb:rawphrase submit}" />
</div>
</div>
</form>
teams.php:
if ($_POST['do'] == 'insertfreeagent')
{
if (!$tmntp['canjointeam'])
{
print_no_permission();
}
$count = $vbulletin->db->query_first("
SELECT COUNT(*) AS countrows
FROM " . TABLE_PREFIX . "tmnt_members
WHERE userid = '".$vbulletin->userinfo['userid']."'
");
if ($count['countrows'] != 0)
{
print_no_permission();
}
$userid = $vbulletin->userinfo['userid'];
$available_day = $vbulletin->input->clean_gpc('p', 'available_day', TYPE_NOHTML);
$available_time = $vbulletin->input->clean_gpc('p', 'available_time', TYPE_NOHTML);
$reason = $vbulletin->input->clean_gpc('p', 'reason', TYPE_NOHTML);
$description = $vbulletin->input->clean_gpc('p', 'description', TYPE_NOHTML);
$game = $vbulletin->input->clean_gpc('p', 'game', TYPE_STR);
if (!$description || !$available_day || !$available_time || !$reason)
{
$_REQUEST['do'] = 'addfreeagent';
$incomplete_fields = true;
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
$vbulletin->db->query_write("INSERT INTO " . TABLE_PREFIX . "tmnt_members
(userid, teamid, time, ip, available_day, available_time, reason, description, game)
VALUES (
'".$vbulletin->db->escape_string($userid)."',
'0',
".TIMENOW.",
'".$vbulletin->db->escape_string($ip)."',
'".$vbulletin->db->escape_string($available_day)."',
'".$vbulletin->db->escape_string($available_time)."',
'".$vbulletin->db->escape_string($reason)."',
'".$vbulletin->db->escape_string($description)."',
'".$vbulletin->db->escape_string($game)."'
)
");
$vbulletin->url = "teams.php?do=freeagents";
eval(print_standard_redirect('redirect_insertfreea gent'));
}
}
I've tried both $vbulletin->input->clean_gpc('p', 'game', TYPE_STR) and $vbulletin->input->clean_gpc('p', 'game', TYPE_NOHTML) with no differences. I really don't understand the rest of this to proceed any further. If anyone could help me determine the issue I would greatly appreciate it.
tmnt_newfreeagent template:
<form class="vbform block" action="teams.php?do=addfreeagent" method="post">
<div class="blockbody formcontrols">
<div class="blockrow">
<label for="game">Game</label>
<div style="overflow:auto">
<input type="checkbox" name="game[]" value="Aliens vs. Predator">Aliens vs. Predator<br />
<input type="checkbox" name="game[]" value="Chivalry: Medeival Warfare">Chivalry: Medeival Warfare<br />
<input type="checkbox" name="game[]" value="Counter-Strike: Global Offensive">Counter-Strike: Global Offensive<br />
<input type="checkbox" name="game[]" value="Insurgency">Insurgency<br />
</div>
<p class="description">Please select the game(s) you play.</p>
</div>
</div>
<div class="blockfoot actionbuttons">
<div class="group">
<input type="submit" class="button" value="{vb:rawphrase submit}" />
</div>
</div>
</form>
teams.php:
if ($_POST['do'] == 'insertfreeagent')
{
if (!$tmntp['canjointeam'])
{
print_no_permission();
}
$count = $vbulletin->db->query_first("
SELECT COUNT(*) AS countrows
FROM " . TABLE_PREFIX . "tmnt_members
WHERE userid = '".$vbulletin->userinfo['userid']."'
");
if ($count['countrows'] != 0)
{
print_no_permission();
}
$userid = $vbulletin->userinfo['userid'];
$available_day = $vbulletin->input->clean_gpc('p', 'available_day', TYPE_NOHTML);
$available_time = $vbulletin->input->clean_gpc('p', 'available_time', TYPE_NOHTML);
$reason = $vbulletin->input->clean_gpc('p', 'reason', TYPE_NOHTML);
$description = $vbulletin->input->clean_gpc('p', 'description', TYPE_NOHTML);
$game = $vbulletin->input->clean_gpc('p', 'game', TYPE_STR);
if (!$description || !$available_day || !$available_time || !$reason)
{
$_REQUEST['do'] = 'addfreeagent';
$incomplete_fields = true;
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
$vbulletin->db->query_write("INSERT INTO " . TABLE_PREFIX . "tmnt_members
(userid, teamid, time, ip, available_day, available_time, reason, description, game)
VALUES (
'".$vbulletin->db->escape_string($userid)."',
'0',
".TIMENOW.",
'".$vbulletin->db->escape_string($ip)."',
'".$vbulletin->db->escape_string($available_day)."',
'".$vbulletin->db->escape_string($available_time)."',
'".$vbulletin->db->escape_string($reason)."',
'".$vbulletin->db->escape_string($description)."',
'".$vbulletin->db->escape_string($game)."'
)
");
$vbulletin->url = "teams.php?do=freeagents";
eval(print_standard_redirect('redirect_insertfreea gent'));
}
}
I've tried both $vbulletin->input->clean_gpc('p', 'game', TYPE_STR) and $vbulletin->input->clean_gpc('p', 'game', TYPE_NOHTML) with no differences. I really don't understand the rest of this to proceed any further. If anyone could help me determine the issue I would greatly appreciate it.