2

I have a sub form in my XML, which works fine in the back end, but I'm not sure of the best way to get the data out of the subform and display it.

Here's part of my original XML

        <field name= "repeatable_fields_map"
               description= "MOD_ACCREDITATIONS_REPEATABLE_FIELDS_MAP_DESC"
               type= "subform"
               label= "MOD_ACCREDITATIONS_REPEATABLE_FIELDS_MAP_LABEL"
               min= "1"
               max= "1000"
               required= "true"
               formsource= "/modules/mod_accreditations/xml/repeatablefieldsmap.xml"
               multiple= "true"
               buttons= "add,remove"
               layout="joomla.form.field.subform.repeatable"
               groupByFieldset="false"/>

Here's my subform

<?xml version="1.0" encoding="UTF-8"?>
<form>
  <field name="accreditationImage"
         type="media"
         label="MOD_ACCREDITATIONS_REPEATABLE_FIELDS_MAP_ACCREDITATION_IMAGE_LABEL"
         description="MOD_ACCREDITATIONS_REPEATABLE_FIELDS_MAP_ACCREDITATION_IMAGE_DESC"/>
  <field name="accreditationText"
         type="text"
         label="MOD_ACCREDITATIONS_REPEATABLE_FIELDS_MAP_ACCREDITATION_TEXT_LABEL"
         description="MOD_ACCREDITATIONS_REPEATABLE_FIELDS_MAP_ACCREDITATION_TEXTE_DESC"/>
  <field name="link"
         type="url"
         label="MOD_ACCREDITATIONS_REPEATABLE_FIELDS_MAP_LINK_LABEL"
         description="MOD_ACCREDITATIONS_REPEATABLE_FIELDS_MAP_LINK_DESC"/>
</form>

Here's how I outpur my $params

<?php echo "<pre>" . print_r($params, true) . "</pre>"; ?>

And here's what arrives

Joomla\Registry\Registry Object
(
    [data:protected] => stdClass Object
        (
            [repeatable_fields_map] => stdClass Object
                (
                    [repeatable_fields_map0] => stdClass Object
                        (
                            [accreditationImage] => images/accreditations/some-logo.jpg
                            [accreditationText] => SomeText
                            [link] => http://www.someurl.com
                        )

                )

            [moduleclass_sfx] => 
            [module_tag] => div
            [bootstrap_size] => 0
            [header_tag] => h3
            [header_class] => 
            [style] => 0
        )

    [initialized:protected] => 1
    [separator] => .
)

I know I need a foreach loop to access them, but I also know I can't use $params directly.

I've looked at other questions such as this: Display values of JFormFieldRepeatable but it seems they use attribs. The thing that confuses me is that I don't see attribs in the XML. Is this a special Joomla! function or am I being a noob?

Other things I read which may help someone: How to get value from Sub Form use Joomla Subform field values in custom field from same module How to save data from subform fieldtype in joomla 3.7 custom field

1
$repeatable_fields_map = (array)$this->params->get('repeatable_fields_map');
foreach($repeatable_fields_map as $item) {
    $accreditationImage = $item->accreditationImage;
    $accreditationText = $item->accreditationText;
    $link = $item->link;
    // do stuff with these variables
}

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.