Actions

API16

JFormRuleEquals/test

From Joomla! Documentation

< API16:JFormRuleEquals
Revision as of 05:15, 30 March 2010 by Doxiki (Talk | contribs)

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 test if two values are equal. To use this rule, the form XML needs a validate attribute of equals and a field attribute that is equal to the field to test against.

[Edit Descripton]

Description:JFormRuleEquals/test

Syntax

test(&$field, &$values)
Parameter Name Default Value Description
&$field $field A reference to the form field.
&$values $values The values to test for validiaty.

Returns

mixed on invalid rule, true if the value is valid, false otherwise.

Defined in

libraries/joomla/form/rules/equals.php

Importing

jimport( 'joomla.form.rules.equals' );

Source Body

public function test(&$field, &$values)
{
        $return = false;
        $field1 = (string)$field->attributes()->name;
        $field2 = (string)$field->attributes()->field;
 
        // Check the rule.
        if (!$field2) {
                return new JException('Invalid Form Rule :: '.get_class($this));
        }
 
        // Test the two values against each other.
        if ($values[$field1] == $values[$field2]) {
                $return = true;
        }
 
        return $return;
}

[Edit See Also] SeeAlso:JFormRuleEquals/test

Examples

<CodeExamplesForm />