Skip to content

Commit

Permalink
Add support for testing field matches in validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Mar 24, 2016
1 parent bbf2af9 commit eca212c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/Element/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit eca212c

Please sign in to comment.