We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Custom multiselect fieldtype doesn't save all values on submit (newbie alert!)

Development and Programming

Manoj Thomas's avatar
Manoj Thomas
185 posts
14 years ago
Manoj Thomas's avatar Manoj Thomas

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

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.