Skip to main content
added 10 characters in body
Source Link
GDP
  • 7.7k
  • 2
  • 30
  • 72

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 checkboxtext 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 varies from equipment type, model, etc. (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,

  1. How is that accomplished ?
  2. Where would be the correct place to do it so that MVC treats it as though it were in the "standard" form XML?
  3. 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);

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 checkbox 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 varies 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,

  1. How is that accomplished ?
  2. Where would be the correct place to do it so that MVC treats it as though it were in the "standard" form XML?
  3. 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);

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,

  1. How is that accomplished ?
  2. Where would be the correct place to do it so that MVC treats it as though it were in the "standard" form XML?
  3. 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);
Source Link
GDP
  • 7.7k
  • 2
  • 30
  • 72

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

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 checkbox 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 varies 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,

  1. How is that accomplished ?
  2. Where would be the correct place to do it so that MVC treats it as though it were in the "standard" form XML?
  3. 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);