Good morning,

I have a question. I create my own fields in my own component. I'm using the "SimpleXMLElement" class. The form generates via getForm work perfectly:

$newfieldset = new SimpleXMLElement('<fieldset></fieldset>');
$newfieldset->addAttribute('name', 'case_customfields');

foreach($customfields as $customfield) 
    $field = $newfieldset->addChild('field');
    $field->addAttribute('name', $customfield->field_name . '-' . $customfield->id);
    $field->addAttribute('type', $customfield->field_type);
    $field->addAttribute('default', $customfield->field_default_value);
    $field->addAttribute('label', $customfield->field_label);
    $field->addAttribute('description', $customfield->field_description);



return $form;  

I also modified the getItem function, which returns values for my own fields:

    $customfields_value = $this->getCustomFieldsValues($pk);

    foreach($customfields_value as $customfield_value) 
        $singleCustomField = $this->getSingleCustomFields($customfield_value->custom_fields_id);
        $field_id = $singleCustomField['id'];
        $field_name = $singleCustomField['field_name'];

        $field = $field_name . '-' . $field_id;
        $item->$field = $customfield_value->value;


    return $item;

Work perfectly too.

The problem is that in the edit form I do not see custom values. If I create a static form in XML (models / forms), the data is. For fields created via "SimpleXMLElement" - data is not in the form.

Of course, I can load data into the form via the "SimpleXMLElement" class in getForm, but that seems to me to be a bad way.

Where do I make a mistake? And thank you in advance for help.


1 Answer 1


My fault. Wrong order. Corectly is: 1. First - create form and transform to SimpleXMLElement

$formXml = new SimpleXMLElement(file_get_contents(JPATH_COMPONENT.'path to xml file'));

  1. Add children element to form
  2. Convert SimpleXMLElement to new XML
  3. New XML (with children) as $form
  4. Return $form

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.