Welcome Guest, Not a member yet? Register   Sign In
How to get values from a multiple select box along with other fields
#1

[eluser]Roy MJ[/eluser]
Can anyone help me with getting values from a multiple select box. The form is as follows

View page:

<form name="choiceForm" method="POST" action="tour_packages/add" >

<select name="destination" multiple="multiple" size="5" style="width:150px">
&lt;?php
foreach($destination as $row)
{
?&gt;
<option value="&lt;?php echo $row->destination?&gt;">&lt;?php echo $row->destination?&gt;</option>
&lt;?php
}
?&gt;
</select>

<label for="days">Days : </label>
&lt;input id="days" type="text" name="days" value="&lt;?php echo (isset($days)) ? $days Confusedet_value('days'); ?&gt;" /&gt;
<span>&lt;?php echo form_error('days'); ?&gt;</span>

<button value="Send" name="Submit" id="submit-go" type="submit">Add</button>



Model looks like this:

function save($type=''){
case 'Add':
$destinations = array ($_POST['destination']);
foreach ($destination as $lang)
{
$destinations[] = $lang ;
}
echo implode(",", $destinations);


$data = array(
'destinations' => implode(",", $destinations),
);
$this->db->insert('tour_package', $data);
}

And controller looks like this :

function add(){
$data['tourcategory'] = $this->Tour_packages_model->select_category();
$data['destination'] = $this->Tour_packages_model->select_destination();
//if data submitted ' '

if($this->input->post('Submit')){
/*$destinations = array ($_POST['destination']);
foreach ($destination as $lang)
{
$destinations[] = $lang ;
}
echo implode(",", $destinations);
*/
$config = array(
array('field' => 'destination', 'label' => 'Destination', 'rules' => '') );


Ive removed other fields from model view and controller.

Currently with the above script im getting only the first value selected. And the values selected are obtained as a space while echoing the query.
#2

[eluser]Victor Michnowicz[/eluser]
I think you need to modify the name attribute:

Code:
<select name="destination[]" multiple="multiple" size="5" style="width:150px">
#3

[eluser]Ochetski[/eluser]
@elvicmic is right... so you will recive all selected values on "destination" as an array, but it will not work on get method, only post.
#4

[eluser]Unknown[/eluser]
hi , actually i am using multi select listbox and i want the selected array in an order in which option is clicked .how is it possible?




Theme © iAndrew 2016 - Forum software by © MyBB