src/Controller/DefaultController.php
protected function runFormValidation(string $sMode, array $aOverrides = []): void
    {
        $aConfig              = $this->getConfig();
        $oModel               = static::getModel();
        $oFormValidation      = Factory::service('FormValidation');
        $aRulesFormValidation = [];
        $aImplementedRules    = [];

        foreach ($aConfig['FIELDS'] as &$oField) {

            if ($sMode === static::EDIT_MODE_CREATE && classUses($oModel, Localised::class)) {
                if ($oField->key == 'locale') {

                    /** @var Locale $oLocale */
                    $oLocale = Factory::service('Locale');
                    /** @var Uri $oUri */
                    $oUri = Factory::service('Uri');
                    if (empty($oUri->segment(5))) {
                        $oField->validation[] = 'is[' . $oLocale->getDefautLocale() . ']';
                    }
                }
            }

            if (array_key_exists($oField->key, $aOverrides)) {
                $sRules            = implode('|', $aOverrides[$oField->key]);
                $aImplementedRules = array_merge($aImplementedRules, $aOverrides[$oField->key]);
            } else {
                $sRules            = implode('|', $oField->validation);
                $aImplementedRules = array_merge($aImplementedRules, $oField->validation);
            }

            $aRulesFormValidation[] = [
                'field' => $oField->key,
                'label' => $oField->label,
                'rules' => $sRules,
            ];
        }

        $oFormValidation->set_rules($aRulesFormValidation);

        //  Load up friendly versions of the form validation rules if they exist
        $aImplementedRules = array_map(
            function ($sRule) {
                return preg_replace('/\[.*\]/', '', $sRule);
            },
            $aImplementedRules
        );
        $aImplementedRules = arrayUniqueMulti($aImplementedRules);

        foreach ($aImplementedRules as $sRule) {
            $sMessage = lang('fv_' . $sRule);
            if ($sMessage) {
                $oFormValidation->set_message($sRule, $sMessage);
            }
        }

        if (!$oFormValidation->run()) {
            throw new ValidationException(lang('fv_there_were_errors'));
        }
    }
protected function runFormValidation(string $sMode, array $aOverrides = []): void
    {
        $aConfig              = $this->getConfig();
        $oModel               = static::getModel();
        $oFormValidation      = Factory::service('FormValidation');
        $aRulesFormValidation = [];
        $aImplementedRules    = [];

        foreach ($aConfig['FIELDS'] as &$oField) {

            if ($sMode === static::EDIT_MODE_CREATE && classUses($oModel, Localised::class)) {
                if ($oField->key == 'locale') {

                    /** @var Locale $oLocale */
                    $oLocale = Factory::service('Locale');
                    /** @var Uri $oUri */
                    $oUri = Factory::service('Uri');
                    if (empty($oUri->segment(5))) {
                        $oField->validation[] = 'is[' . $oLocale->getDefautLocale() . ']';
                    }
                }
            }

            if (array_key_exists($oField->key, $aOverrides)) {
                $sRules            = implode('|', $aOverrides[$oField->key]);
                $aImplementedRules = array_merge($aImplementedRules, $aOverrides[$oField->key]);
            } else {
                $sRules            = implode('|', $oField->validation);
                $aImplementedRules = array_merge($aImplementedRules, $oField->validation);
            }

            $aRulesFormValidation[] = [
                'field' => $oField->key,
                'label' => $oField->label,
                'rules' => $sRules,
            ];
        }

        $oFormValidation->set_rules($aRulesFormValidation);

        //  Load up friendly versions of the form validation rules if they exist
        $aImplementedRules = array_map(
            function ($sRule) {
                return preg_replace('/\[.*\]/', '', $sRule);
            },
            $aImplementedRules
        );
        $aImplementedRules = arrayUniqueMulti($aImplementedRules);

        foreach ($aImplementedRules as $sRule) {
            $sMessage = lang('fv_' . $sRule);
            if ($sMessage) {
                $oFormValidation->set_message($sRule, $sMessage);
            }
        }

        if (!$oFormValidation->run()) {
            throw new ValidationException(lang('fv_there_were_errors'));
        }
    }
Form validation for edit/create

@param string $sMode      The mode in which the validation is being run
@param array  $aOverrides Any overrides for the fields; best to do this in the model's describeFields() method

@return void
@throws ValidationException