API16:JForm/getInstance
From Joomla! Documentation
Description
Method to get an instance of a form.
<! removed transcluded page call, red link never existed >
Syntax
static getInstance($data, $name= 'form', $file=true, $options=array())
| Parameter Name | Default Value | Description |
|---|---|---|
| $data | $name The name of the form. | |
| $name | 'form' | $data The name of an XML file or an XML string. |
| $file | true | $file Flag to toggle whether the $data is a file path or a string. |
| $options | array() | $options An array of options to pass to the form. |
Returns
object A instance.
Defined in
libraries/joomla/form/form.php
Importing
jimport( 'joomla.form.form' );
Source Body
public static function getInstance($data, $name = 'form', $file = true, $options = array())
{
static $instances;
if ($instances == null) {
$instances = array();
}
// Only load the form once.
if (!isset($instances[$name])) {
// Instantiate the form.
$instances[$name] = new JForm($options);
// Set the form name.
$instances[$name]->setName($name);
// Load the data.
if ($file) {
$instances[$name]->load($data, true, true);
} else {
$instances[$name]->load($data, false, true);
}
}
return $instances[$name];
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples