I have a requirement to generate a page/form based on the user's list of items. As is, the user can specify a list of items that have a text description of the item, and whether it's a text
or list
field type. (Imagine a list of equipment that can be checked out, and the list of items to check varies by the type of equipment. There are certainly some shared items, but they vary from equipment type, model, etc.). So, instead of simply loading an existing XML file from the models\forms\
folder and running with it, can a new fieldset and a series of new fields be added on the fly.
If so,
- How is that accomplished ?
- Where would be the correct place to do it so that MVC treats it as though it were in the "standard" form XML?
- How best to retrieve a list of those fields for displaying in the View?
models\myform.php
$form = $this->loadForm('com_mycomponent.myform', 'myform', array('control' => 'jform', 'load_data' => $loadData));
controllers/myform.php
// Get the user data.
$data = JFactory::getApplication()->input->get('jform', array(), 'array');
// Validate the posted data.
$form = $model->getForm();
if (!$form) {
JError::raiseError(500, $model->getError());
return false;
}
...
// Validate the posted data.
$data = $model->validate($form, $data);
...
// Attempt to save the data.
$return = $model->save($data);