Actions

API16

JModelForm/validate

From Joomla! Documentation

< API16:JModelForm
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Method to validate the form data.

[Edit Descripton]

Description:JModelForm/validate

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;
}

[Edit See Also] SeeAlso:JModelForm/validate

Examples

<CodeExamplesForm />