JModelForm/validate
From Joomla! Documentation
< API16:JModelForm
The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Method to validate the form data.
Syntax[edit]
validate($form, $data)
Parameter Name | Default Value | Description |
---|---|---|
$form | $form The form to validate against. | |
$data | $data The data to validate. |
Returns[edit]
mixed Array of filtered data if valid, false otherwise.
Defined in[edit]
libraries/joomla/application/component/modelform.php
Importing[edit]
jimport( 'joomla.application.component.modelform' );
Source Body[edit]
function validate($form, $data)
{
// Filter and validate the form data.
$data = $form->filter($data);
$return = $form->validate($data);
// Check for an error.
if (JError::isError($return)) {
$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;
}
return $data;
}
Examples[edit]
Code Examples[edit]