Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When I was looking for the same, I found this very well working generic Validator for Identical Fields. I don't find it now so I just post the code... </p> <pre><code>&lt;?php class Zend_Validate_IdenticalField extends Zend_Validate_Abstract { const NOT_MATCH = 'notMatch'; const MISSING_FIELD_NAME = 'missingFieldName'; const INVALID_FIELD_NAME = 'invalidFieldName'; /** * @var array */ protected $_messageTemplates = array( self::MISSING_FIELD_NAME =&gt; 'DEVELOPMENT ERROR: Field name to match against was not provided.', self::INVALID_FIELD_NAME =&gt; 'DEVELOPMENT ERROR: The field "%fieldName%" was not provided to match against.', self::NOT_MATCH =&gt; 'Does not match %fieldTitle%.' ); /** * @var array */ protected $_messageVariables = array( 'fieldName' =&gt; '_fieldName', 'fieldTitle' =&gt; '_fieldTitle' ); /** * Name of the field as it appear in the $context array. * * @var string */ protected $_fieldName; /** * Title of the field to display in an error message. * * If evaluates to false then will be set to $this-&gt;_fieldName. * * @var string */ protected $_fieldTitle; /** * Sets validator options * * @param string $fieldName * @param string $fieldTitle * @return void */ public function __construct($fieldName, $fieldTitle = null) { $this-&gt;setFieldName($fieldName); $this-&gt;setFieldTitle($fieldTitle); } /** * Returns the field name. * * @return string */ public function getFieldName() { return $this-&gt;_fieldName; } /** * Sets the field name. * * @param string $fieldName * @return Zend_Validate_IdenticalField Provides a fluent interface */ public function setFieldName($fieldName) { $this-&gt;_fieldName = $fieldName; return $this; } /** * Returns the field title. * * @return integer */ public function getFieldTitle() { return $this-&gt;_fieldTitle; } /** * Sets the field title. * * @param string:null $fieldTitle * @return Zend_Validate_IdenticalField Provides a fluent interface */ public function setFieldTitle($fieldTitle = null) { $this-&gt;_fieldTitle = $fieldTitle ? $fieldTitle : $this-&gt;_fieldName; return $this; } /** * Defined by Zend_Validate_Interface * * Returns true if and only if a field name has been set, the field name is available in the * context, and the value of that field name matches the provided value. * * @param string $value * * @return boolean */ public function isValid($value, $context = null) { $this-&gt;_setValue($value); $field = $this-&gt;getFieldName(); if (empty($field)) { $this-&gt;_error(self::MISSING_FIELD_NAME); return false; } elseif (!isset($context[$field])) { $this-&gt;_error(self::INVALID_FIELD_NAME); return false; } elseif (is_array($context)) { if ($value == $context[$field]) { return true; } } elseif (is_string($context) &amp;&amp; ($value == $context)) { return true; } $this-&gt;_error(self::NOT_MATCH); return false; } } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload