From d51f4c0fa5f488b46b950dd767bbd41acda08e7c Mon Sep 17 00:00:00 2001 From: Vance Lucas Date: Mon, 11 Nov 2013 15:02:19 -0600 Subject: [PATCH] Always use custom label in place of field name Fixes: https://github.com/vlucas/valitron/issues/32 --- src/Valitron/Validator.php | 4 ++++ tests/Valitron/ValidateTest.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) 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 */