/** * @inheritdoc */ public function validate(ValidationItem $validationItem) { $value1 = $validationItem->getValue(); $value2 = $validationItem->findValue($this->sameElement); if ($value2 !== $value1) { $message = new Validation\Message("Fields %_tested-field_% and %_compare-field_% have different values", ["tested-field" => $validationItem->getElement()->getName(true, true), "compare-field" => $this->sameElement], self::DIFFERENT); $validationItem->appendMessage($message); return false; } return true; }
/** * @inheritdoc */ public function validate(ValidationItem $validationItem) { $value = $validationItem->getValue(); $length = strlen($value); if ($this->minLength > 0 && $length < $this->minLength) { $message = new Validation\Message('String too short (less than %_min-length_% character)', ["min-length" => $this->minLength, "string-length" => $length], self::TOO_SHORT); $validationItem->appendMessage($message); return false; } if ($this->maxLength > 0 && $length > $this->maxLength) { $message = new Validation\Message('String too long (more than %_max-length_% character)', ["max-length" => $this->maxLength, "string-length" => $length], self::TOO_LONG); $validationItem->appendMessage($message); return false; } return true; }