From eca212caf248302e470e29482e6fba319a708309 Mon Sep 17 00:00:00 2001 From: Nick Sagona Date: Wed, 23 Mar 2016 20:57:35 -0500 Subject: [PATCH] Add support for testing field matches in validation --- src/Element/AbstractElement.php | 10 ++++++++-- src/Form.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Element/AbstractElement.php b/src/Element/AbstractElement.php index 192e15a..51fb59b 100644 --- a/src/Element/AbstractElement.php +++ b/src/Element/AbstractElement.php @@ -467,10 +467,11 @@ public function addValidators(array $validators) /** * Validate the form element object * + * @param array $fields * @throws Exception * @return boolean */ - public function validate() + public function validate(array $fields = []) { $this->errors = []; @@ -504,7 +505,12 @@ public function validate() // If Pop\Validator\* if ($validator instanceof \Pop\Validator\ValidatorInterface) { - if ('Pop\Validator\NotEmpty' == get_class($validator)) { + if (('Pop\Validator\Equal' == get_class($validator)) && array_key_exists($validator->getValue(), $fields)) { + $validator->setValue($fields[$validator->getValue()]); + if (!$validator->evaluate($curElemValue)) { + $this->errors[] = $validator->getMessage(); + } + } else if ('Pop\Validator\NotEmpty' == get_class($validator)) { if (!$validator->evaluate($curElemValue)) { $this->errors[] = $validator->getMessage(); } diff --git a/src/Form.php b/src/Form.php index 6b46582..6a86423 100644 --- a/src/Form.php +++ b/src/Form.php @@ -640,7 +640,7 @@ public function isValid() // Check each element for validators, validate them and return the result. foreach ($children as $child) { - if ($child->validate() == false) { + if ($child->validate($this->fields) == false) { $noErrors = false; } }