API16

JFormRuleEquals/test: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===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 agai...
 
m preparing for archive only
 
(3 intermediate revisions by 2 users not shown)
Line 2: Line 2:
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.
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.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JFormRuleEquals/test|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JFormRuleEquals/test}}
 
<! removed transcluded page call, red link never existed >


===Syntax===
===Syntax===
Line 17: Line 15:
!Description
!Description
|-
|-
|  
| &$field
|  
|  
|  $field A reference to the form field.  
|  $field A reference to the form field.  
|-
|-
|  
| &$values
|  
|  
|  $values The values to test for validiaty.  
|  $values The values to test for validiaty.  
Line 56: Line 54:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JFormRuleEquals/test|Edit See Also]]<nowiki>]</nowiki>
<! removed transcluded page call, red link never existed >
</span>
{{SeeAlso:JFormRuleEquals/test}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=test
  category=test
  category=JFormRuleEquals
  category=JFormRuleEquals
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>
[[Category:Archived pages API16]]

Latest revision as of 01:43, 25 March 2017

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.


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

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


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

Examples

Code Examples