Back to Form class

Method loadFile

public bool
loadFile
(mixed $file, mixed $reset = true, mixed $xpath = null)
Method to load the form description from an XML file.
Parameters
  • string $file The filesystem path of an XML file.
  • bool $reset Flag to toggle whether form fields should be replaced if a field already exists with the same group/name.
  • string $xpath An optional xpath to search for the fields.
Returns
  • bool True on success, false otherwise.
Since
  • 1.7.0
Class: Form
Project: Joomla

Method loadFile - Source code

/**
 * Method to load the form description from an XML file.
 *
 * The reset option works on a group basis. If the XML file references
 * groups that have already been created they will be replaced with the
 * fields in the new XML file unless the $reset parameter has been set
 * to false.
 *
 * @param   string   $file   The filesystem path of an XML file.
 * @param   boolean  $reset  Flag to toggle whether form fields should be replaced if a field
 *                           already exists with the same group/name.
 * @param   string   $xpath  An optional xpath to search for the fields.
 *
 * @return  boolean  True on success, false otherwise.
 *
 * @since   1.7.0
 */
public function loadFile($file, $reset = true, $xpath = null)
{
    // Check to see if the path is an absolute path.
    if (!is_file($file)) {
        // Not an absolute path so let's attempt to find one using JPath.
        $file = Path::find(self::addFormPath(), strtolower($file) . '.xml');
        // If unable to find the file return false.
        if (!$file) {
            return false;
        }
    }
    // Attempt to load the XML file.
    $xml = simplexml_load_file($file);
    return $this->load($xml, $reset, $xpath);
}