API16

Difference between revisions of "JFormValidator/validate"

From Joomla! Documentation

< API16:JFormValidator
m (removing red link to edit, no existant pages)
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JFormValidator/validate|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JFormValidator/validate}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 84: Line 84:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JFormValidator/validate|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JFormValidator/validate}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 99: Line 99:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Revision as of 21:54, 13 May 2013

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 a group of fields.

[<! removed edit link to red link >]

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

Syntax[edit]

validate(&$fields, &$data)
Parameter Name Default Value Description
&$fields $fields An array of fields to validate.
&$data $data The data to validate.

Returns[edit]

mixed Array on success, on error.

Defined in[edit]

libraries/joomla/form/formvalidator.php

Importing[edit]

jimport( 'joomla.form.formvalidator' );

Source Body[edit]

public function validate(&$fields, &$data)
{
        $results = array();

        foreach ($fields as $name => $field) {
                // Get the data for the field.
                $value = array_key_exists($name, $data) ? $data[$name] : null;

                // Check if the field is required.
                if ((string)$field->attributes()->required == 'true') {
                        // Check if the field value is empty.
                        if ($value === '') {
                                // The required field is empty!
                                if ($message = (string)$field->attributes()->message) {
                                        $results[] = new JException(JText::_($message), 0, E_WARNING);
                                } else {
                                        $results[] = new JException(JText::sprintf('Libraries_Form_Validator_Field_Required', JText::_((string)$field->attributes()->name)), 0, E_WARNING);
                                }

                                // We don't want to display more than one message per field so continue to the next one.
                                continue;
                        }
                }

                // Run the field validator.
                $return = $this->_isValid($field, $data);

                // Check for an error.
                if (JError::isError($return)) {
                        return $return;
                }

                // Check if the field is valid.
                if ($return === false) {
                        // The field failed validation.
                        if ($message = (string)$field->attributes()->message) {
                                $results[] = new JException(JText::_($message), 0, E_WARNING);
                        } else {
                                $results[] = new JException(JText::sprintf('Libraries_Form_Validator_Field_Invalid', (string)$field->attributes()->name), 0, E_WARNING);
                        }
                }
        }

        return $results;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

<CodeExamplesForm />