From Joomla! Documentation

< API16:JForm
Revision as of 17:50, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.


Method to validate form data.

[Edit Descripton]



validate($data, $limit=null)
Parameter Name Default Value Description
$data $data An array of field values to validate.
$limit null $limit An option group to limit the validation to.


mixed Boolean on success, on error.

Defined in



jimport( 'joomla.form.form' );

Source Body

public function validate($data, $limit = null)
        $return = true;
        $data   = (array)$data;
        // Check if the group exists.
        if ($limit !== null && !isset($this->_groups[$limit])) {
                // The group that was supposed to be filtered does not exist.
                return new JException(JText::sprintf('LIBRARIES FORM VALIDATOR GROUP NOT FOUND', $limit), 0, E_ERROR);
        // Get a validator object.
        $validator = new JFormValidator();
        // Iterate through the groups.
        foreach ($this->_groups as $group => $fields) {
                // Filter if no group is specified or if the group matches the current group.
                if ($limit === null || ($limit !== null && $group === $limit)) {
                        // If the group name matches the name of a group in the data and the value is not scalar, pass the group.
                        if (isset($data[$group]) && !is_scalar($data[$group]) && !is_resource($data[$group])) {
                                $results = $validator->validate($this->_groups[$group], $data[$group]);
                        } else {
                                // Run the validator over the group.
                                $results = $validator->validate($this->_groups[$group], $data);
                        // Check for a error.
                        if (JError::isError($results)) {
                                return new JException($results->getMessage(), 0, E_ERROR);
                        // Check the validation results.
                        if (count($results)) {
                                // Get the validation messages.
                                foreach ($results as $result) {
                                        if (JError::isError($result) && $result->get('level') === E_WARNING) {
                                                $return = false;
        return $return;

[Edit See Also] SeeAlso:JForm/validate


<CodeExamplesForm />