Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

process_custom_fields_submission()

Description

Process posted custom fields

Parameters

ColumnTypeDefaultDescription
$fields array List of custom fields
$submitted boolean Processing submitted fields?

Return

array Returns collection of items with the extra "html_properties" key

Location

include/request_functions.php lines 1128 to 1166

Definition

 
function process_custom_fields_submission(array $fields$submitted)
    {
    return 
array_map(function($field) use ($submitted)
        {
        global 
$lang$FIXED_LIST_FIELD_TYPES;

        
$field["value"] = trim(getval($field["html_properties"]["name"], ""));

        if(
in_array($field["type"], $FIXED_LIST_FIELD_TYPES))
            {
            
// The HTML id and name are basically identical (@see gen_custom_fields_html_props() ). If field is of fixed 
            // list type, then the name prop will be appended with "[]". For this reason, when we call getval() we need 
            // to use the elements' ID instead.
            
$submitted_data getval($field["html_properties"]["id"], array());

            
// Find the selected options
            
$field["selected_options"] = array_filter($field["options"], function($option) use ($field$submitted_data)
                {
                
$computed_value md5("{$field["html_properties"]["id"]}_{$option}");
                if(
in_array($computed_value$submitted_data))
                    {
                    return 
true;
                    }

                return 
false;
                });

            
$field["value"] = implode(", "$field["selected_options"]);
            }

        if(
$submitted && $field["required"] && $field["value"] == "")
            {
            
$field["error"] = str_replace("%field"i18n_get_translated($field["title"]), $lang["researchrequest_custom_field_required"]);
            return 
$field;
            }

        return 
$field;
        }, 
gen_custom_fields_html_props(get_valid_custom_fields($fields)));
    }

This article was last updated 13th July 2020 15:35 Europe/London time based on the source file dated 26th June 2020 11:03 Europe/London time.