In this example, we're only creating an XML file and allowing the plugin to dynamically generate a table from it. I haven't tested this much past basic functionality, so don't expect it to magically conjure a complex table. This is suitable for basic table structures and not much else. The alternative is to design your own output, which is in another example. However, we're going to explore the most basic XMLForm field - using only an XML file.
The XML File
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="basic">
<field type="text" name="title" default="" label="Title" description="Enter a title" />
<field type="text" name="description" default="" label="Description" description="Enter a description" />
<field type="text" name="url" default="" label="URL" description="Enter a URL" />
<field type="text" name="image" default="" label="Image" description="Enter an image URL" />
</fieldset>
</form>
As you can see, this is a very basic XML form, only containing text elements because this is what will render best in the table. If you were to include radios, or checkboxes - it wouldn't render well. If you're going to use the default table output, you need to consider the fields you're using. Single select lists, url fields, integer fields - all fine. Media fields, checkboxes - probably won't render in a way that will look any kind of good.
Setting up the Field
Now that you have an XML form, it's time to set up the field. This is probably the easiest part of the entire process, for any XMLForm. Before we get started, know that this field type has very few options. Everything else you're used to using to manipulate custom fields is applicable to XMLForm fields. So we won't be going over normal field configurations, focusing only on XMLForm specific fields.
Let's start with a screenshot, and move on to explaining every field we changed.
Starting at the top, obviously your field needs a name, which auto-populates the label field.
The Type is XMLForm (xmlform), which causes Joomla to reload with the XMLForm options. Let's work our way down the list:
- Form Source:
- This is the JPATH_ROOT path to your XML file.
- I like to keep all of my XMLForm files in a single subdirectory under the Joomla root, just so it's easy to find them. As long as they're under the root and you know the path, they can be anywhere you want. In this case, the field is in subforms/example_xmlonly.xml
- Load Language:
- We aren't loading a language file. That is in a different example.
- Load Template:
- We aren't loading a template. Because this is set to No, the plugin will attempt to build a table.
- Groupby Fieldset:
- This groups the parameters by fieldset in the generated form. Not applicable in this example, but will be explored in other examples.
- Multiple:
- We turned this on, because we're exploring the table output. It works for custom templates as well, it's just a convenient option to enable for this example.
- Layout:
- how the subform is displayed.
- Minimum Items & Maximum Items: self explanatory
- Show Buttons: allows add/remove/move buttons on the displayed subform.
What it looks like
As you can see, the form renders like you'd expect. If we had chosen other fields, Joomla would have rendered them as it does in any other part of Joomla - because this field is built using the same Joomla internals as any other form.
The Output
The screenshots are from my development server, but this form actually exists and has been configured for this article category. The list contains only 2 items, but the form field was configured with a maximum of 99, so this list COULD be quite long if we wanted to fill it in.
The actual XMLForm output is below:
Example XML Only:
Title
Description
URL
Image
Title One
The First Description
https://example.com
https://example.com/image.jpg
Title Two
The Second Description
https://example.net
https://example.net/image.webp
As you can see, this field type can be used in extremely simple ways to achieve pretty fabulous results.