Welcome Guest, Not a member yet? Register   Sign In
Form not submitt select list items
#1

[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>
        &lt;?=form_error('club_name')?&gt;
      <p><label for="club_name">Club Name:</label>
     &lt;input type="text" name="club_name"  size="35" value="&lt;?php echo set_value('club_name', $club['club_name']); ?&gt;" /&gt;
      </p>
</fieldset>

<fieldset>

<legend>Board</legend>
      <p><label for="chairman">Chairman:</label>
      &lt;input type="text" name="chairman"  size="35" value="&lt;?php echo set_value('chairman', $club['chairman']); ?&gt;" /&gt;
      </p>
  
      <p><label for="secretary">Secretary Name:</label>
      &lt;input type="text" name="secretary"  size="35" value="&lt;?php echo set_value('secretary', $club['secretary']); ?&gt;" /&gt;
      </p>
</fieldset>

<fieldset>
<legend>Teams</legend>

<table width="100%" border="0" cellpadding="0">
  <tr>
    <td width="40%">
      Unselected
      &lt;?=form_dropdown('unselected_teams', (array) $unselected_teams, NULL, 'multiple="multiple" size="15" id="select_left" style="width:100%"');?&gt;
    </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
    &lt;?=form_dropdown('selected_teams[]', (array) $selected_teams, NULL, 'multiple="multiple" size="15" id="select_right" style="width:100%"');?&gt;</td>
  </tr>
</table>

</fieldset>

     &lt;input type="submit" name="Submit" class="submit" value="save" /&gt;
     &lt;input type="button" name="back" class="submit" value="back"&gt;
&lt;/form&gt;

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');
        }
    }
#2

[eluser]wabu[/eluser]
Mr. Norris,

You might try adding the following to the top of edit() to see what's being posted:

Code:
print_r($_POST);
#3

[eluser]Scott Boyde[/eluser]
Maybe I should have posted that I have echoed out the $_POST

Code:
Array ( [ID_CLUB] => 127 [club_name] => Upperlands FC [chairman] => [secretary] => [unselected_teams] => 1472 )
#4

[eluser]Zack Kitzmiller[/eluser]
Build that drop down by hand and see what happens.

Also, show the the HTML that CI is actually building using the form helper. Might be able to help better.
#5

[eluser]Scott Boyde[/eluser]
[quote author="techneke" date="1254861298"]Build that drop down by hand and see what happens. [/quote]

Will try and remember how I do that, CI makes things so much easier.

[quote author="techneke" date="1254861298"]
Also, show the the HTML that CI is actually building using the form helper. Might be able to help better.[/quote]

Apologies but how do I do that.
#6

[eluser]Zack Kitzmiller[/eluser]
Just view the source, and copy and paste it..
#7

[eluser]Scott Boyde[/eluser]
I knew as soon as I posted that I was going to regret it.

Code:
&lt;form method=“post” action=“http://www.nifootball.co.uk/admin/clubs/edit/127.html”&gt;
&lt;input type=‘hidden’ name=‘ID_CLUB’ id=‘ID_CLUB’ value=‘127’ &gt;

&lt;input type=“submit” name=“Submit” class=“submit” value=“save” /&gt;
&lt;input type=“button” name=“back” class=“submit” value=“back”&gt;

<fieldset>
<legend>Club:</legend>

          <label for=“club_name”>Club Name:</label>
    &lt;input type=“text” name=“club_name”  size=“35” value=“Upperlands FC” /&gt;
  
</fieldset>

<fieldset>

<legend>Board</legend>
    <label for=“chairman”>Chairman:</label>
    &lt;input type=“text” name=“chairman”  size=“35” value=”” /&gt;

  

    <label for=“secretary”>Secretary Name:</label>
    &lt;input type=“text” name=“secretary”  size=“35” value=”” /&gt;
  
</fieldset>

<fieldset>
<legend>Teams</legend>

<table width=“100%” border=“0” cellpadding=“0”>
  <tr>

  <td width=“40%”>
    Unselected
    <select name=“unselected_teams” multiple=“multiple” size=“15” id=“select_left” style=“width:100%”>
<option value=“269”>100th OB</option>
<option value=“1185”>103rd YM</option>
<option value=“1188”>104th</option>
<option value=“246”>104th OB</option>
<option value=“993”>104th OB</option>
<option value=“361”>10th OB</option>
</select>  </td>
  <td style=“text-align:center; vertical-align:middle;”>
    void(0);“id=“options_right” ]Add >><br><br>

    void(0);“id=“options_left” ]<< Remove
  </td>
  <td width=“40%”>
  Selected
  <select name=“selected_teams[]” multiple=“multiple” size=“15” id=“select_right” style=“width:100%”>
</select></td>
  </tr>
</table>

</fieldset>

    &lt;input type=“submit” name=“Submit” class=“submit” value=“save” /&gt;
    &lt;input type=“button” name=“back” class=“submit” value=“back”&gt;
&lt;/form&gt;
#8

[eluser]Scott Boyde[/eluser]
I built the select by hand and still get the same issue not selected_teams submitted.

It seems a strange problem, that it works fine locally but not on my live server. And to make it worse I have the same code but different options and this works fine.




Theme © iAndrew 2016 - Forum software by © MyBB