Source for file form.php
Documentation is available at form.php
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Method to checkin a row.
* @param integer $pk The numeric id of the primary key.
* @return boolean False on failure or error, true otherwise.
public function checkin($pk =
null)
// Only attempt to check the row in if it exists.
// Get an instance of the row to checkin.
// Check if this is the user having previously checked out the row.
if ($table->checked_out >
0 &&
$table->checked_out !=
$user->get('id') &&
!$user->authorise('core.admin', 'com_checkin'))
$this->setError(JText::_('JLIB_APPLICATION_ERROR_CHECKIN_USER_MISMATCH'));
// Attempt to check the row in.
if (!$table->checkin($pk))
* Method to check-out a row for editing.
* @param integer $pk The numeric id of the primary key.
* @return boolean False on failure or error, true otherwise.
// Only attempt to check the row in if it exists.
// Get an instance of the row to checkout.
// If there is no checked_out or checked_out_time field, just return true.
// Check if this is the user having previously checked out the row.
if ($table->checked_out >
0 &&
$table->checked_out !=
$user->get('id'))
$this->setError(JText::_('JLIB_APPLICATION_ERROR_CHECKOUT_USER_MISMATCH'));
// Attempt to check the row out.
if (!$table->checkout($user->get('id'), $pk))
* Abstract method for getting the form from the model.
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return mixed A JForm object on success, false on failure
abstract public function getForm($data =
array(), $loadData =
true);
* Method to get a form object.
* @param string $name The name of the form.
* @param string $source The form source. Can be XML string if file flag is set to false.
* @param array $options Optional array of options for the form creation.
* @param boolean $clear Optional argument to force load a new form.
* @param string $xpath An optional xpath to search for the fields.
* @return mixed JForm object on success, False on error.
protected function loadForm($name, $source =
null, $options =
array(), $clear =
false, $xpath =
false)
// Handle the optional arguments.
// Create a signature hash.
// Check if we can use a previously loaded form.
if (isset
($this->_forms[$hash]) &&
!$clear)
if (isset
($options['load_data']) &&
$options['load_data'])
// Get the data for the form.
// Allow for additional modification of the form, and events to be triggered.
// We pass the data because plugins may require it.
// Load the data into the form after the plugins have operated.
// Store the form for later.
* Method to get the data that should be injected in the form.
* @return array The default data is an empty array.
* Method to allow derived classes to preprocess the data.
* @param string $context The context identifier.
* @param mixed &$data The data to be processed. It gets altered directly.
// Get the dispatcher and load the users plugins.
// Trigger the data preparation event.
$results =
$dispatcher->trigger('onContentPrepareData', array($context, $data));
// Check for errors encountered while preparing the data.
$this->setError($dispatcher->getError());
* Method to allow derived classes to preprocess the form.
* @param JForm $form A JForm object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
* @throws Exception if there is an error in the form event.
protected function preprocessForm(JForm $form, $data, $group =
'content')
// Import the appropriate plugin group.
// Trigger the form preparation event.
$results =
$dispatcher->trigger('onContentPrepareForm', array($form, $data));
// Check for errors encountered while preparing the form.
$error =
$dispatcher->getError();
if (!($error instanceof
Exception))
throw
new Exception($error);
* Method to validate the form data.
* @param JForm $form The form to validate against.
* @param array $data The data to validate.
* @param string $group The name of the field group to validate.
* @return mixed Array of filtered data if valid, false otherwise.
public function validate($form, $data, $group =
null)
// Filter and validate the form data.
$data =
$form->filter($data);
$return =
$form->validate($data, $group);
if ($return instanceof
Exception)
// Check the validation results.
// Get the validation messages from the form.
foreach ($form->getErrors() as $message)
// Tags B/C break at 3.1.2
if (isset
($data['metadata']['tags']) &&
!isset
($data['tags']))
$data['tags'] =
$data['metadata']['tags'];
Documentation generated on Tue, 19 Nov 2013 15:03:38 +0100 by phpDocumentor 1.4.3