Welcome Guest, Not a member yet? Register   Sign In
Populate form_multiselect from SET values ?
#3

(01-19-2021, 09:47 PM)iRedds Wrote: $sdept = explode(',', $fieldFromTable)


Thanks mate , I have already tried that but there was some additional steps in order for it to work and you neede to do the
explode function in the edit form.

So in case someone is interested or having the same problem:

1. In the update function of your controller you need to pass an additional array
from the row with the SET data (from db)  to your view $data

PHP Code:
$sdept = array();

        $data['sdept']=$data['db_row']['Department']; 

2. In your  edit view you make your multiform item  same as in create form
but you explode the data from the controller in the selected items:
PHP Code:
echo form_label('Select Department''Department');
$dept = array(
                  'DPT1' => '1',
                  'DPT2' => '2',
                  'DPT3' => '3',
                  'DPT4' => '4',
                  'DPT5' => '5',
                  'DPT6' => '6');
                  $selected explode(",",$sdept);
                  echo form_multiselect('Department[]'$dept$selected); 


3. In your model you need again to implode the data again before updating

PHP Code:
'date' => $this->input->post('date'),
            'No' => $this->input->post('No'),
            'Act' => $this->input->post('Act'),
            'Category' => $this->input->post('Category'),
            'Department' => implode(",",$dept),
            // 'Department' => $this->input->post('Department'),
            'Desc' => $this->input->post('Desc'),
            'Remarks' => $this->input->post('Remarks'),
        );
        $id =  $this->input->post('id');
        $this->db->where('id'$id);
        return $this->db->Update('Near'$data); 


At least this is working for me so far . I don't know if there is a more elegant way to achieve
the same result.
Reply


Messages In This Thread
RE: Populate form_multiselect from SET values ? - by stepgr - 01-20-2021, 12:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB