diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index 1ee80ca..d80a544 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -465,6 +465,10 @@ class Validator if($param instanceof \DateTime) { $param = $param->format('Y-m-d'); } + // Use custom label instead of field name if set + if(isset($this->_labels[$param])) { + $param = $this->_labels[$param]; + } $values[] = $param; } diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index 0c1f41a..a474b04 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -545,6 +545,23 @@ class ValidateTest extends BaseTestCase ), $v->errors()); } + public function testCustomLabelArrayWithoutMessage() + { + $v = new Valitron\Validator(array( + 'password' => 'foo', + 'passwordConfirm' => 'bar' + )); + $v->rule('equals', 'password', 'passwordConfirm'); + $v->labels(array( + 'password' => 'Password', + 'passwordConfirm' => 'Password Confirm' + )); + $v->validate(); + $this->assertEquals(array( + 'password' => array("Password must be the same as 'Password Confirm'"), + ), $v->errors()); + } + /** * Custom rules and callbacks */