From 86cdecf19372357e177c09bc30cd5312c5475cc0 Mon Sep 17 00:00:00 2001 From: Willem Wollebrants Date: Thu, 6 Jul 2017 11:21:27 +0200 Subject: [PATCH] Always run 'accepted' validation (#101) --- src/Valitron/Validator.php | 6 +++++- tests/Valitron/ValidateTest.php | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Valitron/Validator.php b/src/Valitron/Validator.php index 0f97ace..ef5b1d7 100644 --- a/src/Valitron/Validator.php +++ b/src/Valitron/Validator.php @@ -945,7 +945,11 @@ class Validator // Don't validate if the field is not required and the value is empty if ($this->hasRule('optional', $field) && isset($values)) { //Continue with execution below if statement - } elseif ($v['rule'] !== 'required' && !$this->hasRule('required', $field) && (! isset($values) || $values === '' || ($multiple && count($values) == 0))) { + } elseif ( + $v['rule'] !== 'required' && !$this->hasRule('required', $field) && + $v['rule'] !== 'accepted' && + (! isset($values) || $values === '' || ($multiple && count($values) == 0)) + ) { continue; } diff --git a/tests/Valitron/ValidateTest.php b/tests/Valitron/ValidateTest.php index e6794d7..2529330 100644 --- a/tests/Valitron/ValidateTest.php +++ b/tests/Valitron/ValidateTest.php @@ -98,6 +98,12 @@ class ValidateTest extends BaseTestCase $this->assertFalse($v->validate()); } + public function testAcceptedNotSet(){ + $v = new Validator(); + $v->rule('accepted', 'agree'); + $this->assertFalse($v->validate()); + } + public function testNumericValid() { $v = new Validator(array('num' => '42.341569'));