Performs server-side validation of the submitted form data.

@param array $data

@return boolean
766618
public function php($data)
    {
        // Is Server-side Validation Enabled?
        
        if (!$this->getServerSide()) {
            return true;
        }
        
        // Initialise:
        
        $valid = true;
        
        // Validate Fields:
        
        foreach ($this->getFormFields() as $field) {
            $valid = ($field->validate($this) && $valid);
        }
        
        // Validate Rules:
        
        foreach ($this->rules as $fieldName => $rules) {
            
            if ($field = $this->getDataField($fieldName)) {
                
                foreach ($rules as $rule) {
                    
                    // Test Field Data:
                    
                    if (!$rule->test($data[$fieldName])) {
                        $this->validationError($fieldName, $rule->getMessage(), 'validation');
                        $valid = false;
                    }
                    
                }
                
            }
            
        }
        
        // Answer Result:
        
        return $valid;
    }
1284317
public function validate($data = null)
  {
    $this->reset();

    if (!$this->isSent($data)) {
      return false;
    }

    if (!$this->checkCaptcha($data)) {
      $this->addError($this->getErrCaptcha());
    }

    $data = $this->beforeValidation($this->getValuesForValidation($data));

    foreach ($this->fields as $field => $el) {
      $el->validate($data[$field]);
      unset($data[$field]);

      $this->data[$field] = $el->getValue(true);

      if ($err = $el->getErrors()) {
        foreach ($err as $str) {
          $this->addError($str);
        }
      }
    }

    // Если остались доп.поля после предвалидации - переносим к общим данным
    if (!empty($data)) {
      $this->data = array_merge($data, $this->data);
    }

    $this->data = $this->afterValidation($this->data);

    if ($this->isValid()) {
      $this->process();

      return $this->isValid();
    }

    return false;
  }
205743
public function validate( array $data ) {
		// Validate use Validator.
		try {
			$this->validate_use_validator( $data, $this->get_validate_rules() );
		} catch ( \Exception $e ) {
			trigger_error( $e->getMessage(), E_USER_WARNING ); // @WPCS: XSS OK.
		}

		// Validate use custom callback.
		$callbacks = $this->fields->pluck( 'validate_cb', 'id' )->filter( 'is_callable' );

		if ( $callbacks->isNotEmpty() ) {
			$this->validate_by_callbacks( $data, $callbacks->all() );
		}
	}
677840
public function validate_submission_data($data) {
        global $DB, $USER;

        $errors = array();
        if (empty($data['id']) and empty($data['example'])) {
            // Make sure there is no submission saved meanwhile from another browser window.
            $sql = "SELECT COUNT(s.id)
                      FROM {workshop_submissions} s
                      JOIN {workshop} w ON (s.workshopid = w.id)
                      JOIN {course_modules} cm ON (w.id = cm.instance)
                      JOIN {modules} m ON (m.name = 'workshop' AND m.id = cm.module)
                     WHERE cm.id = ? AND s.authorid = ? AND s.example = 0";

            if ($DB->count_records_sql($sql, array($data['cmid'], $USER->id))) {
                $errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop');
            }
        }
        // Get the workshop record by id or cmid, depending on whether we're creating or editing a submission.
        if (empty($data['workshopid'])) {
            $workshop = $DB->get_record_select('workshop', 'id = (SELECT instance FROM {course_modules} WHERE id = ?)',
                    [$data['cmid']]);
        } else {
            $workshop = $DB->get_record('workshop', ['id' => $data['workshopid']]);
        }

        if (isset($data['attachment_filemanager'])) {
            $getfiles = file_get_drafarea_files($data['attachment_filemanager']);
            $attachments = $getfiles->list;
        } else {
            $attachments = array();
        }

        if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
            if (empty($attachments)) {
                $errors['attachment_filemanager'] = get_string('err_required', 'form');
            }
        } else if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_DISABLED && !empty($data['attachment_filemanager'])) {
            $errors['attachment_filemanager'] = get_string('submissiontypedisabled', 'mod_workshop');
        }

        if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_REQUIRED && html_is_blank($data['content_editor']['text'])) {
            $errors['content_editor'] = get_string('err_required', 'form');
        } else if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_DISABLED && !empty($data['content_editor']['text'])) {
            $errors['content_editor'] = get_string('submissiontypedisabled', 'mod_workshop');
        }

        // If neither type is explicitly required, one or the other must be submitted.
        if ($workshop->submissiontypetext != WORKSHOP_SUBMISSION_TYPE_REQUIRED
                && $workshop->submissiontypefile != WORKSHOP_SUBMISSION_TYPE_REQUIRED
                && empty($attachments) && html_is_blank($data['content_editor']['text'])) {
            $errors['content_editor'] = get_string('submissionrequiredcontent', 'mod_workshop');
            $errors['attachment_filemanager'] = get_string('submissionrequiredfile', 'mod_workshop');
        }

        return $errors;
    }
1020648
public function validate(array $data)
    {
        $validator = $this->getValidator();
        if (!$validator->count()) {
            //@codingStandardsIgnoreStart
            $validator = @$this->validator();
        }
        $this->_errors = $validator->errors($data);

        return count($this->_errors) === 0;
    }
1264921
protected function validate(array $data)
    {
        $validator = $this->validator->make(
            $data,
            [
                'username' => 'min:6|max:60',
                'password' => 'min:6|max:255',
                'email' => 'email|max:100'
            ]
        );

        if ($validator->fails()) {
            $message = sprintf(
                'Invalid user credentials. %s',
                implode(' ', $validator->errors()->all())
            );
            throw new UserException($message);
        }
    }
1194675
public function parseData(array $data)
    {
        $newData = [];

        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $value = $this->parseData($value);
            }

            // If the data key contains a dot, we will replace it with another character
            // sequence so it doesn't interfere with dot processing when working with
            // array based validation rules and array_dot later in the validations.
            if (Str::contains($key, '.')) {
                $newData[str_replace('.', '->', $key)] = $value;
            } else {
                $newData[$key] = $value;
            }
        }

        return $newData;
    }
1120623
public function check($data)
    {
        $this->validAttribs   = array();
        $this->invalidAttribs = array();
        $this->missingAttribs = array();
        $this->unknownAttribs = array();
        $requiredDependent    = array();
        $seenAttrib           = array();

        foreach (U::flatten($data) as $attribName => $value) {
            $attrib = $this->dataFilter->getAttrib($attribName);
            if (!$attrib) {
                $parts = explode(U::$FLATTEN_SEPARATOR, $attribName);
                $count = count($parts);
                if ($count > 1) {

                    for ($i = $count -1; $i >= 1; $i--) {
                        $testName = join(U::$FLATTEN_SEPARATOR, array_splice($parts, 0, $i));
                        $attrib   = $this->dataFilter->getAttrib($testName. U::$FLATTEN_SEPARATOR. '*');
                        if ($attrib) {
                            break 1;
                        }
                    }
                }
            }
            $seenAttrib[$attribName] = true;

            // unknown attrib
            if (!$attrib) {
                $this->unknownAttribs[$attribName] = $this->dataFilter->applyFilter('pre', $value);
                continue;
            }

            // run pre-filters
            if ($attrib->useFilters()) {
                $value = $this->dataFilter->applyFilter('pre', $attrib->applyFilter('pre', $value));
            }

            // successfull check
            if ($attrib->check($value)) {
                $this->validAttribs[$attribName] = array(
                    'value'  => $attrib->useFilters()
                        ? $this->dataFilter->applyFilter('post', $attrib->applyFilter('post', $value))
                        : $value,
                    'attrib' => &$attrib
                );

                // determine possible dependents
                $attrib->determineDependents($value, $requiredDependent);
            }

            // checks failed
            else {
                $this->invalidAttribs[$attribName] = array(
                    'value'  => $value,
                    'attrib' => &$attrib,
                    'error'  => $attrib->getError()
                );
            }
        }

        // check now all attribs for required
        foreach ($this->dataFilter->getAttribs() as $attribName => $attrib) {

            // already seen
            if (isset($seenAttrib[$attribName])) {
                continue;
            }

            // has default
            elseif (!is_null($default = $attrib->getDefault())) {
                $this->validAttribs[$attribName] = ['value' => $default, 'attrib' => &$attrib];
            }

            // required -> missing
            elseif ($attrib->isRequired() || isset($requiredDependent[$attribName])) {
                $parts = explode(U::$FLATTEN_SEPARATOR, $attribName);
                $count = count($parts);
                if ($count > 1 && $parts[$count-1] === '*') {
                    $before = join(U::$FLATTEN_SEPARATOR, array_splice($parts, 0, $count - 1)). U::$FLATTEN_SEPARATOR;
                    $seen   = array_filter(array_keys($seenAttrib), function ($check) use ($before) {
                        return strpos($check, $before) === 0;
                    });
                    if (count($seen) > 0) {
                        continue;
                    }
                }
                $this->missingAttribs[$attribName] = array(
                    'attrib' => &$attrib,
                    'error'  => $attrib->getMissingText()
                );
            }
        }

        /*error_log("INVALID: ". count($this->invalidAttribs));
        error_log("MISSING: ". count($this->missingAttribs));*/
        return !$this->hasError();
    }
700700
public function validateResponseData($data)
    {
        if (!isset($data->status)) {
            throw EventValidationResponseCorruptDataException::eventApiResponseCorrupt($data);
        } elseif (isset($data->errors)) {
            throw EventValidationResponseErrorException::eventApiResponseError($data->errors[0]);
        }
    }
1371385
protected function validateData()
    {
        $field = 'data';

        if ($this->isExcluded($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if (!isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        if (!is_array($value)) {
            $this->setErrorInvalid($field, $this->translation->text('Data'));
            return false;
        }

        return true;
    }
1372806
public function validates($data = null)
    {
        $this->errors = array();

        // Get data if it wasn't passed
        if ($data === null) {
            $data = $this->data();
        }

        foreach (static::$_validates as $field => $validations) {
            Validations::run($this, $field, $validations);
        }

        return count($this->errors) == 0;
    }
778433
private function _validateColumn(array $data)
    {
        if (!isset($data['label'])) {
            return 'Label key is required.';
        }
        if (!isset($data['index'])) {
            return 'Index key is required.';
        }

        if (isset($data['renderer']) && (!$data['renderer'] instanceof \Closure && !is_string($data['renderer']))) {
            return 'Renderer must be a string or instance of Closure object.';
        }

        if (isset($data['filter']) && !$data['filter'] instanceof \Closure) {
            return 'Filter function must be instance of Closure object.';
        }

        return true;
    }
980540
public function validate($data) {
        global $DB, $SITE;
        $cleaned = clean_param($data, PARAM_TEXT);
        if ($cleaned === '') {
            return get_string('required');
        }
        if ($this->name ==='shortname' &&
                $DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data, $SITE->id))) {
            return get_string('shortnametaken', 'error', $data);
        }
        if ("$data" == "$cleaned") { // implicit conversion to string is needed to do exact comparison
            return true;
        } else {
            return get_string('validateerror', 'admin');
        }
    }
1045339
public function validate($data) {
        if (empty($data)) {
            return true;
        }

        $scss = new core_scss();
        try {
            $scss->compile($data);
        } catch (Leafo\ScssPhp\Exception\ParserException $e) {
            return get_string('scssinvalid', 'admin', $e->getMessage());
        } catch (Leafo\ScssPhp\Exception\CompilerException $e) {
            // Silently ignore this - it could be a scss variable defined from somewhere
            // else which we are not examining here.
            return true;
        }

        return true;
    }
1210221
public function validate(array $data = []) : array
    {
        $validated = false;
        $errors = [];

        if (empty($this->requiredFields)) {
            $errors[] = "Missing requiredFields in the report object";
        }

        foreach ($this->requiredFields as $field) {
            if (!isset($data['info'][$field])) {
                $errors[] = "Required field [$field] must be set";
            }

            if (empty($data['info'][$field])) {
                $errors[] = "Required Field [$field] cannot be empty";
            }
        }

        if (empty($errors)) {
            $validated = true;
            $this->errors = [];
        } else {
            $this->errors = $errors;
        }

        return ['status' => $validated, 'messages' => $errors];
    }
1007930
public function create(array $data)
    {
        if ( $this->validator->with($data)->passes() )
        {
            $data['permissions'] = explode(',', $data['permissions']);
            $this->permission->create($data);
            return true;
        }
        else
        {
            return false;
        }
    }
561681
public function validate(array $data) : bool
    {
        $passed = true;
        $this->invalidFields = [];
        $rules = $this->getRules();
        foreach ($rules as $validation => $fields) {
            foreach ($fields as $key => $value) {
                $field = $this->getFieldInfo($key, $value);
                $validationInstance = $this->getValidation($validation);
                $validationStatus = $validationInstance->run($field, $data);
                $passed = $passed && $validationStatus;
                $this->invalidFields = array_merge_recursive(
                        $this->invalidFields, $validationInstance->getMessages()
                );
            }
        }
        return $passed;
    }