'1', 'PARENT_2'=>'0') */ public function __construct($fieldValues) { $this->_fieldValues = $fieldValues; $this->_messageTemplates = [ self::KEY_IS_EMPTY => _("Value is required and can't be empty"), ]; } /** * Implements Zend_Validate_Abstract. * Given names and expected values of the fields we're depending on ($_fieldValues), * this function returns true if the expected values doesn't match the actual user input, * or if $value is not empty. Returns false otherwise. * * @param string $value - this field's value * @param array $context - names and values of the rest of the fields in this form * * @return bool - true if valid; false otherwise */ public function isValid($value, $context = null) { if ($value != '') { return true; } if (is_array($context)) { foreach ($this->_fieldValues as $fieldName => $fieldValue) { if (!isset($context[$fieldName]) || $context[$fieldName] != $fieldValue) { return true; } } } elseif (is_string($context)) { if (!isset($context) || $context != $fieldValue) { return true; } } $this->_error(self::KEY_IS_EMPTY); return false; } }