Saving A Multi-Select Field in a Custom Joomla 3.X Component
First we want to make sure the XML is set for your multi-select field. Here is an example of the field:
Once this has been completed, we want to handle the data (array) being passed before saying. So let’s go to the views controller file!
If the postSaveHook()
is not present, create it.
Inside this function we cant to take the multi-select value, which is an array and implode()
it!
Make sure the function ends with $model->save($data);
After that, it should be saving properly in the database. Now to show it correctly whenever you edit the item again… We are going to head to the views model file.
Make sure the following is inside the protected function loadFormData()
And just like that, we are done. That was easy right? Post in the comments below if you have any questions!