I was able to create dynamically the form fields by retrieving them from the database by using this as a guide:

How can I dynamically generate a form's XML from PHP?

I just want to know on how get and set values for the custom fields?

also, I want to convert them to JSON format to store in a database field.

Here is my current situation:

My requirement is to make a form dynamic as possible by means of:

Adding custom fields to the edit form depending on the set-up on the back-end: - On the back end, I have a Reports Table, and then I have a Fields table which has a foreign key associated with Reports. Every time I add an item in the Fields table, i have a toggle column to indicate whether that Field I added will be added as a custom field when choosing a report.

If example I have a Regions field as a line item to a report, when I select the report, I will need to add the custom Regions field as an additional selection.

2 Answers 2


how can I access these fields in my loadFormData() function?

Actually loadFormData() is used to get the data for the form, but not the form by itself. Why do you need access your custom fields in this method?

how can I modify the values of the custom fields before saving? I want to convert them to JSON format to store in a database field.

At the top of the file include Registry class:

use Joomla\Registry\Registry;

Then in your save() function:

if (isset($data['custom_field']))
    $registry = new Registry;
    $data['custom_field'] = (string) $registry;

Where $data is your input data. See my answer to the same question here.

  • actually I just used the example loadFormData function, I only want to get and set the values for the custom field that I will use. I will edit my question for better understanding Commented Dec 9, 2014 at 8:55
  • I can't use $data['name of custom field']. It does not return a value. Commented Dec 9, 2014 at 9:26
  • Please update your question with more info and code. Your custom fields are available in some admin form? How do you save your form? Commented Dec 9, 2014 at 14:27
  • since the $data variable only includes the fields that are loaded from a table, the custom fields that I created on the fly are not included in the $data variable. The custom fields are only available in the front-end side based from what fields I have configured in the back-end (Administration side) Commented Dec 10, 2014 at 1:23
  • I was now able to get and set the custom fields value by using $form->getValue() and $form->setValue(). My only problem now is how I can access the $form object in my save() in order to perform the encoding of JSON Format for the custom fields Commented Dec 10, 2014 at 3:46

I was now able to access my created custom fields after creating them in my loadForm function by using this code:

JFactory::getApplication()->input->get('jform', array(), 'array');

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.