I’m trying fudge with the cki_sitelist fieldtype, but I have zero skills. By default, the fieldtype adds a dropdown where the user can select an MSM site. I’m working on a project where the user needs to be able to select multiple sites.
The display_field function looks like this:
public function display_field($data)
{
$text_direction = ($this->settings['field_text_direction'] == 'rtl') ? 'rtl' : 'ltr';
$site_list = array();
//Get the list of sites from the database
$this->EE->db->select('site_id, site_label, site_name');
$this->EE->db->from('exp_sites');
$this->EE->db->order_by('site_label asc');
$q = $this->EE->db->get();
//No need to check if there are no sites. If no results are returned
//then there are more serious problems at hand than this fieldtype going wrong...
//Create blank option
$site_list[''] = "None";
foreach($q->result_array() as $site)
{
$site_list[$site['site_name']] = $site['site_id']." - ".$site['site_label'];
}
return form_dropdown($this->field_name, $site_list, $data, 'dir="'.$text_direction.'" id="'.$this->field_id.'"' );
}I updated the last line to this:
return form_multiselect($this->field_name.'[]', $site_list, $data, 'dir="'.$text_direction.'" id="'.$this->field_id.'"' );This obviously produces a multiselect field in the publish screen, but when I save the entry only one selection from the list gets saved. Do I need to have more code to repopulate the saved data? I contacted Chris, the developer, and he said it shouldn’t be too difficult. I think he might try to help me, but I was trying to figure it out myself.
Thanks! Manoj
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.