Creating a multidimensional JForm field dynamicaly

by Mike   Last Updated October 01, 2019 16:10 PM - source

Item Model

protected function preprocessForm(JForm $form, $data, $group = 'examplegroup')
{
    foreach ($data as $i => $item) {
        $field = new \SimpleXMLElement('<field />');
        $field->addAttribute('name', 'sample[' . $i . ']');
        $field->addAttribute('class', 'input-mini');
        $field->addAttribute('type', 'number');
        $form->setField($field, 'data');
        $form->setValue('sample[' . $i . ']', 'examplegroup', $item->fieldname);
        ...
    }
    ...
}

Layout

<?php foreach ($this->items->data as $i => $item) : ?>
<?php echo $this->form->getInput('sample[' . $i . ], 'examplegroup'); ?>

Output

<input type="number" name="jform[examplegroup][sample[0]]" value="6" class="input-mini">

How can I achieve getting this kind of name name="jform[examplegroup][sample][0]" ? The form needs to be generated dynamicaly and not by writing the name static into the code.



Related Questions


Set New XML attribute in custom JFormField

Updated April 21, 2015 21:04 PM



Store fields data in JSON

Updated May 18, 2015 21:04 PM

username from ID

Updated August 03, 2015 14:04 PM