4

I'm trying to use the Joomla subform field with multiple="true" on (instead of using the old modal repeatable method).

My problem is that the data is not saving to the database. I have read multiple examples but cannot see what I'm doing wrong.

If I turn off multiple="true" then the subform saves data as a JSON string to the database just fine. When I turn it back on, it won't save no matter what I try.

My issue is basically this one, but there were no solutions and I don't have enough reputation to simply comment on it: Why doesn't my subform field data get saved?

My component XML:

<field name="list_links_url" 
        type="subform"
        label="Subform Field" 
        description="Subform Field Description"
        layout="joomla.form.field.subform.repeatable-table"
        multiple="true"
        formsource="/administrator/components/com_products/model/form/subforms/subform_list_links.xml" 
    />

Subform XML:

<?xml version="1.0" encoding="UTF-8"?>
<form>
        <field name="link"
            label="Link"
            type="text"
            description="Enter a URL" 
        />
</form>

FYI - Brand new install of Joomla 3.6.5 and PHP 7.0.10

Any help would be greatly appreciated.

1
  • There is nothing wrong with the code you posted above. Can you say where you are using it? Frontend or backend? In config or passing it to a controller task? etc. Feb 20, 2017 at 7:53

2 Answers 2

3

In your table's bind function, add this:

if ( ( !empty( $array[ 'list_links_url' ] ) && ( is_array( $array[ 'list_links_url' ] ) ) ) ) {
            $this->_jsonEncode[] = "list_links_url";
        }
1
  • This is the closest to a solution I've come across, thanks for taking the time. In the end I've chosen to use the old repeatable method but this is still useful, thanks.
    – sigil
    Apr 24, 2017 at 18:11
2

I know this is an old issue, but since a came across this post on my own research I would like to share my solution. Unfortunately I cannot trace back at which Joomla version this possibility was implemented.

Just add the following line to the beginning of your corresponding table class. With this information the bind method of the Joomla core table class will convert the specified fields by itself.

protected $_jsonEncode = array('fieldname');

In the end its the same as in Stuart Steedman post, but you don't have to override the core bind method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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