[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">
<?php
foreach($destination as $row)
{
?>
<option value="<?php echo $row->destination?>"><?php echo $row->destination?></option>
<?php
}
?>
</select>
<label for="days">Days : </label>
<input id="days" type="text" name="days" value="<?php echo (isset($days)) ? $days
et_value('days'); ?>" />
<span><?php echo form_error('days'); ?></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.