Gdn_Validation::defineValidationFields PHP Method

defineValidationFields() protected method

Fills $this->_ValidationFields with field names that exist in the $PostedFields collection.
protected defineValidationFields ( array $PostedFields, boolean $Insert = false ) : array
$PostedFields array The associative array collection of field names to add.
$Insert boolean A boolean value indicating if the posted fields are to be inserted or updated. If being inserted, the schema's required field rules will be enforced.
return array Returns the subset of {@link $PostedFields} that will be validated.
    protected function defineValidationFields($PostedFields, $Insert = false)
    {
        $Result = array();
        // Start with the fields that have been explicitly defined by `ApplyRule`.
        foreach ($this->_FieldRules as $Field => $Rules) {
            $Result[$Field] = val($Field, $PostedFields, null);
        }
        // Add all of the fields from the schema.
        foreach ($this->getSchemaRules() as $Field => $Rules) {
            $FieldInfo = $this->_Schema[$Field];
            if (!array_key_exists($Field, $PostedFields)) {
                $Required = in_array('Required', $Rules);
                // Don't enforce fields that aren't required or required fields during a sparse update.
                if (!$Required || !$Insert) {
                    continue;
                }
                // Fields with a non-null default can be left out.
                if (val('Default', $FieldInfo, null) !== null || val('AutoIncrement', $FieldInfo)) {
                    continue;
                }
            }
            $Result[$Field] = val($Field, $PostedFields, null);
        }
        return $Result;
    }