4

I can add a multiple select field to my plugin's xml file, like this for countries but when I save it, it only saves the value "array" in the parameters. I would like to save it as a comma separated list, OR an array. I just want it to save values, and restore the chosen selections on editing.

 <field
                name="country"
                type="sql"
                id="country"
                description="MYMUSE_FIELD_COUNTRY_DESC"
                filter="string"
                default="CAN"
                multiple="true" 
                size="8"
                label="MYMUSE_FIELD_COUNTRY_LABEL"
                message="MYMUSE_FIELD_COUNTRY_MESSAGE"
                query="SELECT country_3_code as value, country_name as country FROM #__mymuse_country 
                ORDER by country"
            />
  • I think that filter="string" is used for '<input />' elements not list boxes. Also try to replace country_3_code with an integer-type column like id and use filter="int_array". Set default="Z" where Z is the id that matches Canada in your table. – Farahmand Nov 19 '14 at 21:34
  • Answered! The filter="string" was the problem. Without that it works as expected. It gets saved, for example, as "country":["AIA","ATG","CAN"], – Gord Fisch Nov 19 '14 at 23:31
4

According to the comments on this question, the answer is to remove filter="string" attribute from XML manifest file.

4

Use value and title (not country) in the sql. I believe your SQL should be as follows:

SELECT country_3_code as value, country_name as title FROM #__mymuse_country ORDER by country

See SQL form field type for other variations that might be more suitable for your need.

  • Thanks for looking. I specify the id="Country". I use this field in a component form and all is well. It seems the plugin cannot save an array in params. Looking for a way to intervene in the save plugin process. I get this in the post: – Gord Fisch Nov 19 '14 at 18:45
  • I get this in the post: [jform] => Array ( [enabled] => 1 [access] => 1 [ordering] => 0 [folder] => mymuse [element] => shipping_standard [params] => Array (.... [country] => Array ( [0] => ALB [1] => BLR ) ) ) [task] => plugin.apply [093bc641cdc06549ef53b4b57bfed980] => 1 – Gord Fisch Nov 19 '14 at 18:50
  • The id is fine, it's the SQL that needs adjustment...you have to use "title", not "country" there. – GDP Nov 19 '14 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.