API16

Difference between revisions of "JForm/validate"

From Joomla! Documentation

< API16:JForm
(New page: ===Description=== Method to validate form data. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> <...)
 
m (preparing for archive only)
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
Method to validate form data.
 
Method to validate form data.
  
<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[Description:JForm/validate|Edit Descripton]]<nowiki>]</nowiki>
 
</span>
 
  
{{Description:JForm/validate}}
+
 
 +
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 85: Line 83:
 
</source>
 
</source>
  
<span class="editsection" style="font-size:76%;">
+
 
<nowiki>[</nowiki>[[SeeAlso:JForm/validate|Edit See Also]]<nowiki>]</nowiki>
+
<! removed transcluded page call, red link never existed >
</span>
 
{{SeeAlso:JForm/validate}}
 
  
 
===Examples===
 
===Examples===
<CodeExamplesForm />
+
=== Code Examples ===
 
<dpl>
 
<dpl>
 
  noresultsheader=\n
 
  noresultsheader=\n
 
  category=validate
 
  category=validate
 
  category=JForm
 
  category=JForm
  category=CodeExample
+
  namespace=CodeExample
 
  category=MethodExample
 
  category=MethodExample
 
  include=*
 
  include=*
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 20:42, 24 March 2017

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 form data.


<! removed transcluded page call, red link never existed >

Syntax[edit]

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.

Returns[edit]

mixed Boolean on success, on error.

Defined in[edit]

libraries/joomla/form/form.php

Importing[edit]

jimport( 'joomla.form.form' );

Source Body[edit]

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.
        jimport('joomla.form.formvalidator');
        $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) {
                                                $this->setError($result);
                                                $return = false;
                                        }
                                }
                        }
                }
        }

        return $return;
}


<! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]