Form Model

It is a method to validate the form data.

  • \JForm $form - The form to validate against.
  • array $data - The data to validate.
  • string $group - The name of the field group to validate.
  • return array|boolean - Array of filtered data if valid, false otherwise.
public function validate($form, $data, $group = null)
{
// Include the plugins for the delete events.
\JPluginHelper::importPlugin($this->events_map['validate']);

$dispatcher = \JEventDispatcher::getInstance();
$dispatcher->trigger('onUserBeforeDataValidation', array($form, &$data));

// Filter and validate the form data.
$data = $form->filter($data);
$return = $form->validate($data, $group);

// Check for an error.
if ($return instanceof \Exception)
{
$this->setError($return->getMessage());

return false;
}

// Check the validation results.
if ($return === false)
{
// Get the validation messages from the form.
foreach ($form->getErrors() as $message)
{
$this->setError($message);
}

return false;
}

// Tags B/C break at 3.1.2
if (!isset($data['tags']) && isset($data['metadata']['tags']))
{
$data['tags'] = $data['metadata']['tags'];
}

return $data;
}