Validate the supplied form model.

@return mixed
973831
protected function validateModel()
    {
        if (!$this->model) {
            throw new ApplicationException(Lang::get(
                'backend::lang.form.missing_model',
                ['class'=>get_class($this->controller)]
            ));
        }

        $this->data = isset($this->data)
            ? (object) $this->data
            : $this->model;

        return $this->model;
    }
955264
public function validate()
    {
        # addValues adds validation errors for unknown values
        $errs = count($this->errors);

        $dataKey = constant(get_called_class()."::EVENT_DATA_KEY");

        if ($this->beforeValidate() !== true) {
            return false;
        }
        foreach ($this->fields as $field) {
            if ($field->validate($this) === false) {
                foreach ($field->getErrors() as $error) {
                    $this->addError($error);
                    $errs++;
                }
            }
        }
        return (
            $errs > 0 ||
            $this->afterValidate() !== true ||
            count($this->errors) > 0
        ) ? false : true;
    }
52668
public function validate() {
        $validated = TRUE;

        foreach($this->getFormElements() as $name => $child) {
            $validated &= $child->validate();
        }

        $validated &= $this->fireEvent("Form\onValidate", [ $this->value, $this ], TRUE, FALSE);

        return (bool)$validated;
    }
1312190
public function validate()
	{
		$this->errors = array();
		$value = $this->getRawValue();

		if ($this->required) {

			$passed = $this->validateRequired($value);

			// don't do anymore validation until it passes the required validation
			if (!$passed) return $this->errors;

			// validate by field type
			$this->validateType($value);

			// validate by pattern, if defined
			$this->validatePattern($value);

      // validate by maxlength, if defined
      $this->validateMaxLength($value);

			// hook for users?

		}

		return $this->errors;
	}
335134
final public function validate(): bool
    {
        // validate csrf token if required
        if ($this->_tokenRequired && !$this->_tokenOk) {
            App::$Session->getFlashBag()->add('warning', __('Hack attention: security token is wrong!'));
            return false;
        }
        // get all rules as array from method rules()
        $rules = $this->rules();
        // get default values of attributes
        $defaultAttr = $this->getAllProperties();

        // start validation: on this step class attribute values will be changed to input data if it valid
        $success = $this->runValidate($rules);

        // get not-passed validation fields as array
        $badAttributes = $this->getBadAttributes();
        // prevent warnings
        if (Any::isArray($badAttributes) && count($badAttributes) > 0) {
            foreach ($badAttributes as $attr) {
                if (Str::contains('.', $attr)) { // sounds like dot-separated array attr
                    $attrName = strstr($attr, '.', true); // get attr name
                    $attrArray = trim(strstr($attr, '.'), '.'); // get dot-based array path

                    $defaultValue = new DotData($defaultAttr); // load default attr

                    $dotData = new DotData($this->{$attrName}); // load local attr variable
                    $dotData->set($attrArray, $defaultValue->get($attr)); // set to local prop. variable default value

                    $this->{$attrName} = $dotData->export(); // export to model
                } else {
                    $this->{$attr} = $defaultAttr[$attr]; // just set ;)
                }
                // add message about wrong attribute to session holder, later display it
                $attrLabel = $attr;
                if ($this->getLabel($attr) !== null) {
                    $attrLabel = $this->getLabel($attr);
                }

                App::$Session->getFlashBag()->add('warning', __('Field "%field%" is incorrect', ['field' => $attrLabel]));
            }
        }

        return $success;
    }
719404
public function validate()
	{
		foreach ($this->validators as $validate)
		{
			$definition = $this->klass->getStaticPropertyValue($validate);
			$this->$validate(wrap_strings_in_arrays($definition));
		}

		$model_reflection = Reflections::instance()->get($this->model);

		if ($model_reflection->hasMethod('validate') && $model_reflection->getMethod('validate')->isPublic())
			$this->model->validate();

		$this->record->clear_model();
		return $this->record;
	}
1321734
public function validate() {

		$app	= Application::getInstance();
		$value	= Input::get($this->name);
		$valid	= TRUE;

		if ($this->required) {
			
			switch ($this->type) {

				default:
				case 'text':
				case 'password':
				case 'date':
				case 'datetime':
				case 'file':
				case 'tel':
				case 'address':
				case 'color':
				case 'hidden':
					if (''==$value) {
						$app->logEvent('Control validation on field “' . $this->name . '” has failed (required)');
						$valid = FALSE;
					}
					break;

				case 'email':
					if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
						$app->logEvent('Control validation on field “' . $this->name . '” has failed (email required)');
						$valid = FALSE;
					}
					break;
					
				case 'url':
					if (!filter_var($value, FILTER_VALIDATE_URL)) {
						$app->logEvent('Control validation on field “' . $this->name . '” has failed (url required)');
						$valid = FALSE;
					}
					break;
					
				case 'number':
					if (!is_numeric($value)) {
						$app->logEvent('Control validation on field “' . $this->name . '” has failed (number required)');
						$valid = FALSE;
					}
					break;
				
				case 'bool':
					break;
					
			}
			
		}

		// set min and max value attribute for date and number only
		if (in_array($this->type, ['number','date'])) {
			
			if ($this->min and $value < $this->min) {
				$app->logEvent('Control validation on field “' . $this->name . '” has failed (min=' . $this->min . ')');
				$valid = FALSE;
			}
			
			if ($this->max and $value > $this->max) {
				$app->logEvent('Control validation on field “' . $this->name . '” has failed (max=' . $this->max . ')');
				$valid = FALSE;
			}
			
		}

		// check validity of minlength attribute
		if ($this->minLength and ''!=$value and strlen($value) < $this->minLength) {
			$app->logEvent('Control validation on field “' . $this->name . '” has failed (minLength=' . $this->minLength . ')');
			$valid = FALSE;
		}

		// check validity of minlength attribute
		if ($this->maxLength and strlen($value) > $this->maxLength) {
			$app->logEvent('Control validation on field “' . $this->name . '” has failed (maxLength=' . $this->maxLength . ')');
			$valid = FALSE;
		}
		
		return $valid;

	}
654834
public function validateValidItem()
    {
        if (!$this->value) {
            return;
        }

        // load allowed values in values_list
        // @todo Imants: Actually we don't need to load all values from Model in
        //       array, just to check couple of posted values.
        //       Probably we should do SELECT * FROM t WHERE id IN ($values) or
        //       something like that to limit array size and time spent on
        //       parsing all DB records in Model.
        $this->getValueList();

        $values = explode($this->separator, $this->value);
        foreach ($values as $v) {
            if (!isset($this->value_list[$v])) {
                $this->displayFieldError("Value $v is not one of the offered values");

                return $this->validate();
            }
        }
    }
1327459
public function checkFormAction()
    {
        $request = $this->getRequest();
        $success = 0;
        $errors = [];

        if ($request->isPost()) {
            $formInputs = $this->getTool('meliscore', 'melis_core_gdpr_tool')->sanitizeRecursive(get_object_vars($request->getPost()), [], true);
            $formConfig = $this->getFormConfig('meliscore/tools/melis_core_gdpr_tool/forms/melis_core_gdpr_search_form', 'melis_core_gdpr_search_form');
            $form = $this->getForm($formConfig);
            $form->setData($formInputs);

            if ($form->isValid()) {
                $success = 1;
            }
            else {
                $errors = $this->getFormErrors($form->getMessages(), $formConfig);
                $success = 0;
            }
        }

        return new JsonModel ([
            'success' =>  $success,
            'errors' => $errors,
        ]);
    }
259141
public function validate()
    {
        $this->debug->groupCollapsed(__METHOD__, $this->attribs['name']);
        $this->props['isValid'] = true;
        $this->classRemove($this->props['attribsContainer'], 'has-error');
        $attribs = $this->attribs;
        if (\in_array($attribs['type'], array('checkbox','radio','select'))) {  // these types use the 'options' array
            $this->validateCrs();
        } elseif (\in_array($attribs['type'], array('submit','reset','image'))) {
            $this->debug->log('not checking');
        } elseif (!empty($this->props['newPage'])) {
            $this->debug->log('not checking newPage');
        } elseif (\in_array($attribs['type'], array('file'))) {
            $this->debug->log($attribs['name'].' is a file type');
            if ($this->isRequired() && empty($attribs['disabled']) && empty($attribs['value'])) {
                $this->flag();
            }
        } elseif ($this->isRequired() || $this->props['flagNonReqInvalid']) {
            if (!empty($attribs['placeholder']) && $attribs['value'] === $attribs['placeholder']) {
                $this->debug->log('value == placeholder');
                $attribs['value'] = null;
            }
            $this->validateFromAttributes();
        }
        if ($this->props['isValid']) {
            $isValid = $this->doValidate();
            // validate callback may call flag() directly
            if ($this->props['isValid'] && !$isValid) {
                $this->flag();
            }
        }
        $this->debug->groupEnd();
        return $this->props['isValid'];
    }
600508
def validate(self, value, model_instance, **kwargs):
        
        self.get_choices_form_class().validate(value, model_instance, **kwargs)
1207372
public function validation()
    {
        $validator = new Validation();

        $validator->add(
            'name',
            new PresenceOf([
                'model' => $this,
                'required' => true,
            ])
        );

        return $this->validate($validator);
    }
1246312
protected function validate()
    {
        foreach ($this->_requiredAttr as $attr) {
            if (is_array($attr)) {
                $valid = false;
                foreach ($attr as $sub) {
                    if (!is_null($this->$sub)) {
                        $valid = true;
                        break;
                    }
                }
                if (!$valid) {
                    return false;
                }
            } elseif (is_null($this->$attr)) {
                return false;
            }
        }
        return true;
    }
685137
public function actionValidate()
    {
        $rr = new RequestResponse();

        if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
            if (\Yii::$app->request->post('sx-model') && \Yii::$app->request->post('sx-model-value')) {
                $modelClass = \Yii::$app->request->post('sx-model');
                $modelValue = \Yii::$app->request->post('sx-model-value');

                /**
                 * @var $modelForm Form2Form
                 */
                $modelForm = $modelClass::find()->where(['id' => $modelValue])->one();
                $modelHasRelatedProperties = $modelForm->createModelFormSend();

                if (method_exists($modelHasRelatedProperties, "createPropertiesValidateModel")) {
                    $model = $modelHasRelatedProperties->createPropertiesValidateModel();
                } else {
                    $model = $modelHasRelatedProperties->getRelatedPropertiesModel();
                }

                return $rr->ajaxValidateForm($model);
            }
        }
    }
751571
protected function getError()
	{
		return $this->form->error(
			$this->model,
			$this->attribute,
			$this->errorOptions,
			$this->enableAjaxValidation,
			$this->enableClientValidation
		);
	}
27563
public function getValidator()
    {
        if (!$this->validator) {
            $this->setValidator(
                $this->validatorFactory->createValidator($this->form)
            );
        }

        return $this->validator;
    }
544368
public function validate()
    {
        $result = new ValidateResult();

        if ($this->get('disabled')) {
            return $result;
        }

        if ($this->required && !$this->checkRequired()) {
            return $result->setMessage(sprintf('Field %s value not allow empty.', $this->getLabel()))
                ->setResult(ValidateResult::STATUS_REQUIRED)
                ->setField($this);
        }

        if ($this->value !== null && $this->value !== '' && $this->validator && !$this->checkRule()) {
            return $result->setMessage(sprintf('Field %s validate fail.', $this->getLabel()))
                ->setResult(ValidateResult::STATUS_FAILURE)
                ->setField($this);
        }

        return $result;
    }