JModelForm/validate: Difference between revisions
From Joomla! Documentation
m clean up |
m preparing for archive only |
||
| Line 4: | Line 4: | ||
===Syntax=== | ===Syntax=== | ||
| Line 62: | Line 62: | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=validate | category=validate | ||
category=JModelForm | category=JModelForm | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
Latest revision as of 01:55, 25 March 2017
Description
Method to validate the form data.
Syntax
validate($form, $data)
| Parameter Name | Default Value | Description |
|---|---|---|
| $form | $form The form to validate against. | |
| $data | $data The data to validate. |
Returns
mixed Array of filtered data if valid, false otherwise.
Defined in
libraries/joomla/application/component/modelform.php
Importing
jimport( 'joomla.application.component.modelform' );
Source Body
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
Code Examples