[eluser]Scott Boyde[/eluser]
Please Forgive the title. :red:
I have a form that I select team(s) from a list and add them to another list to be a member of a club. For some reason when I submit the form the second list (selected_teams) never gets passed into the controller. Can anyone see any issues with the following.
My view
Code:
[removed]
$(document).ready(function() {
$("#select_left").multiSelect("#select_right", {trigger: "#options_right"});
$("#select_right").multiSelect("#select_left", {trigger: "#options_left"});
});
[removed]
<form method="post" action="<?=site_url('admin/clubs/edit/'. $club['ID_CLUB'])?>">
<input type='hidden' name='ID_CLUB' id='ID_CLUB' value='<?= $club['ID_CLUB']; ?>' >
<input type="submit" name="Submit" class="submit" value="save" />
<input type="button" name="back" class="submit" value="back">
<fieldset>
<legend>Club:</legend>
<?=form_error('club_name')?>
<p><label for="club_name">Club Name:</label>
<input type="text" name="club_name" size="35" value="<?php echo set_value('club_name', $club['club_name']); ?>" />
</p>
</fieldset>
<fieldset>
<legend>Board</legend>
<p><label for="chairman">Chairman:</label>
<input type="text" name="chairman" size="35" value="<?php echo set_value('chairman', $club['chairman']); ?>" />
</p>
<p><label for="secretary">Secretary Name:</label>
<input type="text" name="secretary" size="35" value="<?php echo set_value('secretary', $club['secretary']); ?>" />
</p>
</fieldset>
<fieldset>
<legend>Teams</legend>
<table width="100%" border="0" cellpadding="0">
<tr>
<td width="40%">
Unselected
<?=form_dropdown('unselected_teams', (array) $unselected_teams, NULL, 'multiple="multiple" size="15" id="select_left" style="width:100%"');?>
</td>
<td style="text-align:center; vertical-align:middle;">
<a id="options_right" href="[removed]void(0);">Add >></a><br/><br/>
<a id="options_left" href="[removed]void(0);"><< Remove</a>
</td>
<td width="40%">
Selected
<?=form_dropdown('selected_teams[]', (array) $selected_teams, NULL, 'multiple="multiple" size="15" id="select_right" style="width:100%"');?></td>
</tr>
</table>
</fieldset>
<input type="submit" name="Submit" class="submit" value="save" />
<input type="button" name="back" class="submit" value="back">
</form>
Controller
Code:
function edit()
{
$club_id = $this->uri->segment(4);
$this->load->library('form_validation');
$this->form_validation->set_rules('club_name', 'Club Name', 'trim|required|htmlspecialchars|min_length[3]|max_length[30]|callback_clubname_check');
$this->form_validation->set_rules('chairman', 'Chairman', 'trim|htmlspecialchars|min_length[3]|max_length[30]');
$this->form_validation->set_rules('secretary', 'Secretary', 'trim|htmlspecialchars|min_length[3]|max_length[30]');
$this->form_validation->set_error_delimiters('<tr><td></td><td><p class="error">', '</p></td></tr>');
if ($this->form_validation->run() == FALSE)
{
$this->data['club'] = $this->club_model->getClub($club_id);
$this->data['unselected_teams'] = array_to_select($this->team_model->getClublessTeams());
$this->data['selected_teams'] = array_to_select($this->team_model->getSelectedTeamsFromClubID($club_id));
$this->data['page_title'] = 'Club Details';
$this->_run('clubs/edit');
}
else
{
$clubInfo = array(
'ID_CLUB' => $this->input->post('ID_CLUB'),
'contact_id' => '',
'club_name' => $this->input->post('club_name'),
'chairman'=> $this->input->post('chairman'),
'secretary' => $this->input->post('secretary')
);
$this->club_model->updateClub($clubInfo['ID_CLUB'], $clubInfo);
$this->club_model->unlinkTeamClub($clubInfo['ID_CLUB']);
if ($this->input->post('selected_teams')):
foreach(array_keys($_POST['selected_teams']) as $i):
$row['selected_teams'] = isset($_POST['selected_teams'][$i]) ? $this->input->xss_clean($_POST['selected_teams'][$i]) : '';
$clubteams[] = $row;
endforeach;
foreach($clubteams as $club_team):
$this->club_model->linkTeamClub($clubInfo['ID_CLUB'], $club_team['selected_teams']);
endforeach;
endif;
$this->session->set_flashdata('msg', ' Club Details Updated');
redirect('admin/clubs');
}
}