Tuesday, October 6, 2015

MultiSelect not showing existing values

CakePHP v2

I've got some code that looks like this

$payoptions = array('merchant'=>'Online via eGate', 'internetbanking'=>'Internet Banking', 'cheque'=>'Cheque or Cash', 'atevent'=>'At the Event');
            $selectedPayOptions = explode(',',$this->data['Contentfee']['payoptions']);
            $selectedPayOptions2 = array();
            foreach($selectedPayOptions as $val){
                $selectedPayOptions2[$val] = $val;
            }
            debug($selectedPayOptions2);

            echo $this->Form->input('payoptions',
                array('label' => 'Payment Options:'
                , 'options' =>$payoptions
                , 'type' =>'select'
                , 'multiple' =>true
                , 'selected' =>$selectedPayOptions2
                , 'default' =>array('merchant')
                ));

I implode the selection to save, and therefore explode to get my currently selected values. However neither the selected nor the default seem to work. Everything looks right to me and all the docs focus on HABTM while this is simply getting a simple list. I could store as separate columns in the database but this is actually the right tool for the job.

Any ideas where it's going wrong?


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: