I need to create a custom form which generates an input / text field foreach position that is stored in the database. My Code for this field so far:
private function buildSubForm(array $positions)
{
// Create a new form instance.
// Instanz des Form-Objekts erstellen
$form = new JForm('gameofficials');
// Build the Form fields based on the positions
foreach ($positions as $position)
{
// Create a new field instance
$xml = new SimpleXMLElement('<field name="position-'.$position->id.'" type="text" label="'.$position->title.'" />');
// Add the field to the form
$form->setField($xml, $group = null, $replace = true, $fieldset = 'default');
}
return ''; // will be replaced by the form
}
So far it's quite simple but i'm getting again and again the following error:
Error: Joomla\CMS\Form\Form::Joomla\CMS\Form\Form::setField xml
is not an instance of SimpleXMLElement
I've checked my code against https://docs.joomla.org/Advanced_form_guide aswell as https://www.techfry.com/joomla/working-with-joomla-forms-using-jform-class
I've also tried to simply insert an empty xml as start and add then the fields which didn't work either.