1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.validate.set.identical">
4 <title>Identical</title>
7 <classname>Zend_Validate_Identical</classname> allows you to validate if a given value is
8 identical with an set haystack.
11 <sect3 id="zend.validate.set.identical.options">
12 <title>Supported options for Zend_Validate_Identical</title>
15 The following options are supported for <classname>Zend_Validate_Identical</classname>:
21 <emphasis><property>token</property></emphasis>: Sets the token with which the
22 input will be validated against.
28 <sect3 id="zend.validate.set.identical.basic">
29 <title>Basic usage</title>
32 To validate if two values are identical you need to set the origin value as haystack.
33 See the following example which validates two strings.
36 <programlisting language="php"><![CDATA[
37 $valid = new Zend_Validate_Identical('origin');
38 if ($valid->isValid($value) {
44 The validation will only then return <constant>TRUE</constant> when both values are
45 100% identical. In our example, when <varname>$value</varname> is 'origin'.
49 You can set the wished token also afterwards by using the method
50 <methodname>setToken()</methodname> and <methodname>getToken()</methodname> to get
55 <sect3 id="zend.validate.set.identical.types">
56 <title>Identical objects</title>
59 Of course <classname>Zend_Validate_Identical</classname> can not only validate strings,
60 but also any other variable type like Boolean, Integer, Float, Array or even Objects.
61 As already noted Haystack and Value must be identical.
64 <programlisting language="php"><![CDATA[
65 $valid = new Zend_Validate_Identical(123);
66 if ($valid->isValid($input)) {
67 // input appears to be valid
74 <title>Type comparison</title>
77 You should be aware that also the type of a variable is used for validation.
78 This means that the string <emphasis>'3'</emphasis> is not identical with the
79 integer <emphasis>3</emphasis>.
83 This is also the case for Form Elements. They are objects or arrays. So you can't
84 simply compare a Textfield which contains a password with an textual password
85 from another source. The Element itself is given as array which also contains
86 additional informations.
91 <sect3 id="zend.validate.set.identical.configuration">
92 <title>Configuration</title>
95 As all other validators also <classname>Zend_Validate_Identical</classname> supports
96 the usage of configuration settings as input parameter. This means that you can
97 configure this validator with an <classname>Zend_Config</classname> object.
101 But this adds one case which you have to be aware. When you are using an array as
102 haystack then you should wrap it within an <property>'token'</property> key when
103 it could contain only one element.
106 <programlisting language="php"><![CDATA[
107 $valid = new Zend_Validate_Identical(array('token' => 123));
108 if ($valid->isValid($input)) {
109 // input appears to be valid
116 The above example validates the integer 123. The reason for this special case is, that
117 you can configure the token which has to be used by giving the
118 <property>'token'</property> key.
122 So, when your haystack contains one element and this element is named
123 <property>'token'</property> then you have to wrap it like shown in the example below.
126 <programlisting language="php"><![CDATA[
127 $valid = new Zend_Validate_Identical(array('token' => array('token' => 123)));
128 if ($valid->isValid($input)) {
129 // input appears to be valid