# fluentform/6.2.9/app/Services/Settings/Validator/Notifications.php

Fluent Forms – Customizable Contact Forms, Survey, Quiz, &amp; Conversational Form Builder, version 6.2.9. 65 lines.

- Page: https://pluginprobe.com/plugins/fluentform/6.2.9/code/app/Services/Settings/Validator/Notifications.php
- Raw: https://pluginprobe.com/plugins/fluentform/6.2.9/raw/app/Services/Settings/Validator/Notifications.php
- Modified: 2023-06-22T15:10:22+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluentform/6.2.9/code/app/Services/Settings/Validator/Notifications.php#L10-L20`.

```php
<?php

namespace FluentForm\App\Services\Settings\Validator;

use FluentForm\Framework\Helpers\ArrayHelper;
use FluentForm\Framework\Validator\Validator;

class Notifications extends Validate
{
    /**
     * Produce the necessary validation rules and corresponding messages
     *
     * @return array
     */
    public static function validations()
    {
        return [
            [
                'sendTo.type'    => 'required',
                'sendTo.email'   => 'required_if:sendTo.type,email',
                'sendTo.field'   => 'required_if:sendTo.type,field',
                'sendTo.routing' => 'required_if:sendTo.type,routing',
                'subject'        => 'required',
                'message'        => 'required',
            ],
            [
                'sendTo.type.required'     => 'The Send To field is required.',
                'sendTo.email.required_if' => 'The Send to Email field is required.',
                'sendTo.field.required_if' => 'The Send to Field field is required.',
                'sendTo.routing'           => 'Please fill all the routing rules above.',
            ],
        ];
    }

    /**
     * Add conditional validations to the validator.
     *
     * @param \FluentForm\Framework\Validator\Validator $validator
     *
     * @return \FluentForm\Framework\Validator\Validator
     */
    public static function conditionalValidations(Validator $validator)
    {
        $validator->sometimes('sendTo.routing', 'required', function ($input) {
            if ('routing' !== ArrayHelper::get($input, 'sendTo.type')) {
                return false;
            }

            $routingInputs = ArrayHelper::get($input, 'sendTo.routing');
            $required = false;

            foreach ($routingInputs as $routingInput) {
                if (!$routingInput['input_value'] || !$routingInput['field']) {
                    $required = true;
                    break;
                }
            }

            return $required;
        });

        return $validator;
    }
}

```
