Returns submitted data from input.

@param  array $fields
@param  array $data
@param  bool  $clear_missing
@return array
430704
protected function prepare_submitted_data( $fields, array $data, $clear_missing ) {
		$submitted = [];

		foreach ( $fields as $field ) {
			if ( $this->maybe_skip_field( $field ) ) {
				continue;
			}

			$value = array_key_exists( $field->get_id(), $data )
				? $data[ $field->get_id() ]
				: null;

			// Treat false as NULL to support binding false to checkboxes.
			// Don't convert NULL to a string here in order to determine later
			// whether an empty value has been submitted or whether no value has
			// been submitted at all. This is important for processing checkboxes
			// and radio buttons with empty values.
			if ( false === $value ) {
				$value = null;
			} elseif ( is_scalar( $value ) ) {
				$value = (string) $value;
			}

			// Perform the sanitization to get sanitized value.
			$sanitized = $field->get_sanitization_value( $value );

			if ( $field->is_group() ) {
				$submitted[ $field->get_id() ] = $this->get_group_values( $field, $sanitized );
			} else {
				$submitted[ $field->get_id() ] = $sanitized;
			}
		}

		// Clear "null" input data.
		if ( $clear_missing ) {
			$submitted = array_filter( $submitted, function ( $value ) {
				return ! is_null( $value );
			} );
		}

		return $submitted;
	}
869
private function check_fields(array $data)
    {
        $ruleset = $this->validation_rules();
        $mismatch = array_diff_key($data, $ruleset);
        $fields = array_keys($mismatch);

        foreach ($fields as $field) {
            $this->errors[] = array(
                'field' => $field,
                'value' => $data[$field],
                'rule' => 'mismatch',
                'param' => null,
            );
        }
    }
299597
protected static function validateDisplayColumns(array $data, array $fields): array
    {
        foreach ($data as $k => $v) {
            if (in_array($v, $fields)) {
                continue;
            }
            unset($data[$k]);
        }

        return $data;
    }
459283
protected function _render_checkbox($data, $current_value)
    {
        if (isset($data['name'])) {
            $name = $data['name'];
        } else {
            throw new MissingFieldException('name');
        }

        if (isset($data['values'])) {
            $values = $data['values'];
        } else {
            throw new MissingFieldException('values');
        }

        $r = PHP_EOL;
        /** @noinspection ForeachSourceInspection */
        foreach ($values as $value => $label) {
            $checked = is_array($current_value) && in_array($value, $current_value, false);
            $r .= '  <label><input type="checkbox"'
                . " name=\"{$name}[]\"  value=\"$value\" "
                . ($checked ? 'checked="checked"' : '')
                . '/><span>' . htmlspecialchars($label) . '</span></label>' . PHP_EOL;
        }

        return $r;
    }
489148
protected function IblockUpdate(array $data, array $fields = null)
    {
        $return = [];

        if (!empty($data['ID'])) {
            $iblock = $this->iblockLocate($data['ID']);
            unset($data['ID']);
        } elseif (!empty($data['CODE'])) {
            $iblock = $this->iblockLocate($data['CODE']);
            unset($data['CODE']);
        } else {
            throw new Exception('You must set iblock CODE param or iblock ID param');
        }

        $ib = new CIBlock();
        $res = $ib->Update($iblock['ID'], $data);
        if ($res) {
            $return[] = "Iblock {$iblock['CODE']}({$iblock['ID']}) updated";
            if ($fields) {
                $return = array_merge(
                    $return,
                    $this->IblockSetFields($iblock['ID'], $fields)
                );
            }
        } else {
            throw new Exception("Can't update {$iblock['CODE']}({$iblock['ID']}) iblock: {$ib->LAST_ERROR}");
        }

        return $return;
    }
1254580
protected function filterFields(&$data, $formKey = false) {
        $keys = array_keys($data);
        foreach ($keys as $key) {
            if ($formKey) {
                $key = $this->_fields[ $key ]['name'];
            }
            if (isset($this->_skips_[ $key ]) && $this->_skips_[ $key ]) {
                unset($data[ $key ]);
            }
        }
    }
807875
protected function build_input($data, array $fields = []){
        $input = $this->get_open_tag($data, $fields);
        $counter = 1;
        foreach( $this->get_options() as $key => $label ){
            $input .= $this->get_option($key, $label, $counter, $data, $fields);
            $counter++;
        }
        $input .= $this->close_tag;
        return $input;
    }
31392
public function validate( array $data ) {

		$errors = [];

		foreach( $this->fields as $field ) {

			$f = $field->name;
			$v = isset($data[$f]) ? $data[$f] : null;

			list($clean, $errors[$f]) = $field->validate($v);

			if( !$errors[$f] )
				$data[$f] = $clean;

		}

		return [
			$data,
			array_filter($errors),
		];

	}
108072
protected function checkReadonlyField(&$data) {
        if(!empty($this->readonlyField)) {
            foreach ($this->readonlyField as $key=>$field){
                if(isset($data[$field]))
                    unset($data[$field]);
            }
        }
        return $data;
    }
189261
protected function _processData(Table $table, array $csvFields, array $data) : array
    {
        $schema = $table->getSchema();
        foreach ($data as $field => $value) {
            if (!empty($csvFields) && in_array($field, array_keys($csvFields))) {
                switch ($csvFields[$field]->getType()) {
                    case 'related':
                        $data[$field] = $this->_findRelatedRecord($table, $field, $value);
                        break;
                    case 'list':
                        $data[$field] = $this->_findListValue($table, $csvFields[$field]->getLimit(), $value);
                        break;
                    case 'country':
                        $data[$field] = $this->_findListValue($table, 'countries', $value);
                        break;
                }
            } else {
                if ('uuid' === $schema->columnType($field)) {
                    $data[$field] = $this->_findRelatedRecord($table, $field, $value);
                } else {
                    $data[$field] = $value;
                }
            }
        }

        return $data;
    }
538914
public function withData(array $data, array $fields = [])
    {
        $clone = clone $this;
        $clone->_fields = !empty($fields) ? \array_intersect_key($data, \array_flip($fields)) : $data;
        $clone->_errors = [];

        return $clone;
    }
350778
protected function isEmpty($field, $data) {
		if (!isset($data[ $field ])) {
			return true;
		}

		$value = $data[ $field ];

		return is_array($value) ? empty ($value) : strlen(trim($value)) == 0;
	}
1129406
public function getUpdateErrors(array $data, array &$errors = [], $fieldset = null)
    {
        $schema = $this->schema;

        if (!is_null($fieldset)) {
            $schema = $fieldset;
        }

        $fields = $schema->getFields();
        $table = $schema->getName();
        $primary = $schema->getPrimaryFieldName();

        if ((!isset($data[$primary]) || !is_numeric($data[$primary])) && !is_null($primary)) {
            $errors[$primary] = 'Invalid ID';
        }

        foreach ($fields as $name => $field) {
            if ($field['field']['type'] === 'fieldset') {
                if (!isset($data[$name])) {
                    continue;
                }

                if (!isset($errors[$name])) {
                    $errors[$name] = [];
                }

                if (isset($field['field']['attributes']['data-multiple'])
                    && !$field['field']['attributes']['data-multiple']
                ) {
                    $errors[$name] = $this->getUpdateErrors(
                        $data[$name],
                        $errors[$name],
                        Fieldset::i($field['field']['parameters'])
                    );

                    if (empty($errors[$name])) {
                        unset($errors[$name]);
                    }

                    continue;
                }

                foreach($data[$name] as $index => $row) {
                    if (!isset($errors[$name][$index])) {
                        $errors[$name][$index] = [];
                    }

                    $errors[$name][$index] = $this->getUpdateErrors(
                        $row,
                        $errors[$name][$index],
                        Fieldset::i($field['field']['parameters'])
                    );

                    if (empty($errors[$name][$index])) {
                        unset($errors[$name][$index]);
                    }
                }

                if (empty($errors[$name])) {
                    unset($errors[$name]);
                }

                continue;
            }

            if (!isset($field['validation'])) {
                continue;
            }

            foreach ($field['validation'] as $validation) {
                if ($validation['method'] === 'required'
                    && array_key_exists($name, $data)
                    && empty($data[$name])
                ) {
                    $errors[$name] = $validation['message'];
                }
            }
        }

        return $this->getOptionalErrors($data, $errors, $fieldset);
    }
1283409
protected function processQueryFields($data, array $fields = array())
    {
        $base = new stdClass();

        if (count($fields) === 0) {
            return $base;
        }

        foreach ($fields as $key => $field) {

            $this->verifyFieldDefined($key, $field);

            if (in_array($field['name'], $this->customfieldgroups)
                || $field['type'] === 'customfield'
            ) {
            } else {
                $base->$field['name'] = $this->processQueryField($data, $field);
            }
        }

        return $this->sortObject($base);
    }
999014
public function populateCreateFields($data) {

        $data['user_id']            = Auth::user()->id;
        $data['priority_id']        = null;
        $data['from_email_address'] = $this->request->input('from_email_address');
        $data['from_name']          = $this->request->input('from_name');
        $data['slug']               = $this->genericCreateSlug($data['subject']);
        $data['sent']               = 0;
        $data['sent_timestamp']     = Carbon::now();
        $data['read']               = 0;
        $data['archived']           = 0;
        $data['created_at']         = Carbon::now();
        $data['created_by']         = Auth::user()->id;
        $data['updated_at']         = Carbon::now();
        $data['updated_by']         = Auth::user()->id;

        return $data;
    }
940190
protected function getFieldsDelta(array $fieldsA, array $fieldsB)
    {
        $currentFields = Collect($fieldsB)->keyBy('name');
        $currentFieldNames = $currentFields->keys()->toArray();

        $requestedFields = Collect($fieldsA)->keyBy('name');
        $requestedFieldNames = $requestedFields->keys()->toArray();

        $updatedFields = $currentFields->whereIn('name', $requestedFieldNames)->all();

        $addedFields = $requestedFields->reject(function ($requestedField) use ($currentFieldNames) {
            return in_array($requestedField->name, $currentFieldNames);
        })->all();

        $deletedFields = $currentFields->reject(function ($currentFields) use ($requestedFieldNames) {
            return in_array($currentFields->name, $requestedFieldNames);
        })->all();

        $fieldChanges = [];

        foreach ($updatedFields as $key => $updatedField) {
            $fieldChanges[] = FieldMigrationChange::compare($updatedField, $requestedFields[$key]);
        }

        foreach ($addedFields as $addedField) {
            $fieldChanges[] = FieldMigrationChange::getAdded($addedField);
        }

        foreach ($deletedFields as $deletedField) {
            $fieldChanges[] = FieldMigrationChange::getDeleted($deletedField);
        }

        return $fieldChanges;
    }
162609
protected function getDataMethod(array $fields)
    {
        $stub = $this->getStubContent('controller-getdata-method');

        $this->replaceFileSnippet($stub, $this->getFileSnippet($fields, '$this'))
            ->replaceValidationRules($stub, $this->getValidationRules($fields))
            ->replaceFillables($stub, $this->getFillables($fields))
            ->replaceBooleadSnippet($stub, $this->getBooleanSnippet($fields))
            ->replaceStringToNullSnippet($stub, $this->getStringToNullSnippet($fields))
            ->replaceRequestNameComment($stub, '')
            ->replaceMethodVisibilityLevel($stub, 'public');

        $stub = str_replace(PHP_EOL . PHP_EOL, PHP_EOL, $stub);

        return $stub;
    }