Im trying to prefill my subform with datarows from the database.


<?xml version="1.0" encoding="utf-8"?>
<form addfieldprefix="Mydestiny\Component\Mydestiny\Site\Field">
        <field name="id" type="text" readonly="true" class="readonly" default="0" description="JGLOBAL_FIELD_ID_DESC"/>

    <field name="contacts" type="subform"
               labelclass="control-label" multiple="true" buttons=" "
               layout="joomla.form.field.subform.repeatable-table" class="uk-table uk-table-middle"


    <?xml version="1.0" encoding="utf-8"?>
           <field name="account" type="radio" default="0" label="" description="" class="btn-group btn-group-yesno">
              <option value="1">ja</option>
            <option value="0">Nee</option>


I tried this:

$form       = Form::getInstance('com_mydestiny.newcustomerform', 'contacts', array('control' => 'jform'));
$input      = Factory::getApplication()->input;
$formValues = $input->getArray(array(
    'jform' => array(
        'contacts' => 'array'

$prefillData = array("contacts" => array("account" => 1));

But that doesn't do anything.
Can anyone help me?

1 Answer 1


You need to put the subform data one array deeper. This is because your subform has multiple attribute which means the data should be represented by multiple rows:

$prefillData = array("contacts" => array(array("account" => 1)));

This should work fine for your case. When reading existing data, be aware that the array keys are built using subform field name suffixed with a numeric index suffix, so the data is stored like this:

    "contacts" => array(
        'contacts0' => array("account" => 1),
        'contacts1' => array("account" => 1),
        // More rows

Your Answer

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

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