# Validation callback problem in CakePHP 4

**URL:** <https://discourse.cakephp.org/t/validation-callback-problem-in-cakephp-4/8718>\
**Category:** Need Help\
**Tags:** help\
**Created:** [December 9, 2020, 5:20pm UTC](https://discourse.cakephp.org/t/validation-callback-problem-in-cakephp-4/8718 "2020-12-09T17:20:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![die7fox](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/die7fox/32/1970_2.png) [@die7fox](https://discourse.cakephp.org/u/die7fox)\
**Post date:** [December 9, 2020, 5:20pm UTC](https://discourse.cakephp.org/t/validation-callback-problem-in-cakephp-4/8718/1 "2020-12-09T17:20:52Z")

</div>

Hello, everyone. I have two fields in a form, one dropdown and one text:

```
echo $this->Form->control('label_id', ['label' => 'Sensitivity Label', 'empty' => true, 'options' => $labels]);
          
echo $this->Form->control('distro_notes', ['label' => 'Distribution Notes (Required if a PROPRIETARY or CONFIDENTIAL label is chosen)']);

```

Field `distro_notes` is only required if certain label types are chosen from the dropdown. There are six available, and `distro_notes` isn’t required for the first two. My validation rule looks like this:

```
$validator
        ->notEmptyString('distro_notes', 'This field is required if a PROPRIETARY or CONFIDENTIAL label is chosen', function ($context) {
            $labelIds = [1,2];
            return !in_array($context['data']['label_id'], $labelIds) && empty($context['data']['distro_notes']);
        });

```

The validation executes on `distro_notes` regardless of which label is chosen, when it should be allowed to remain empty if `label_id` == 1 or 2. What am I missing?
