Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 1146 to 1178

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"], [], false'is_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 17th November 2024 15:35 Europe/London time based on the source file dated 27th September 2024 12:30 Europe/London time.