Collections functions
General functions
Node functions
Render functions
Theme permission functions
User 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 1151 to 1183

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)
                {
                return 
in_array(md5("{$field["html_properties"]["id"]}_{$option}"), $submitted_data);
                });

            
$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 19th March 2024 11:35 Europe/London time based on the source file dated 28th February 2024 10:20 Europe/London time.