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?
$ctx: array
$ctx array Contextual information (e.g. change the prefix for html tags' identifiers)

Return

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

Location

include/request_functions.php lines 1150 to 1187

Definition

 
function process_custom_fields_submission(array $fields$submitted, array $ctx): array
    {
    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 && ($error hook('process_custom_fields_submission_validator''', [$field]))) {
            
// Allow plugins to validate (their own) custom field types or override existing behaviour
            
$field['error'] = $error;
        } elseif (
$submitted && $field['required'] && $field['value'] == '') {
            
$field['error'] = str_replace(
                
'%field',
                
i18n_get_translated($field['title']),
                
$lang['researchrequest_custom_field_required']
            );
        }

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

This article was last updated 11th December 2024 11:35 Europe/London time based on the source file dated 18th November 2024 16:40 Europe/London time.