updateFields2 (function)

Last updated: Fri, May 26, 2023 10:27 am
Return to Knowledgebase

Purpose

The updateFields2 function in UserSpice is used to process and sanitize the fields of a POST request, excluding any fields specified in the $skip array.

Location

users/helpers/us_helpers.php

Parameters

# Parameter Data Type Required Description
1 $post array Yes The POST data containing the fields to be processed.
2 $skip = [] array Yes An array of fields to be skipped and not included in the processed fields.

Returns

Data Type Description of Returned Data
array An array containing the processed and sanitized fields.

Further Documentation:

// Process and sanitize the fields of a POST request, excluding 'password' and 'confirm_password' fields
$requestData = $_POST;
$skippedFields = ['password', 'confirm_password'];

$processedFields = updateFields2($requestData, $skippedFields);

// Use the processed fields for further operations
foreach ($processedFields as $field => $value) {
echo "Field: $field, Value: $value
";
}


In the example above, the updateFields2 function is used to process and sanitize the fields of a POST request ($_POST array). The $skippedFields array specifies the fields to be skipped during processing (e.g., sensitive fields like passwords). The function returns an array ($processedFields) containing the processed and sanitized fields.

In the example, the processed fields are iterated over, and their field names and values are displayed using a simple foreach loop. You can modify the code to perform specific operations on the processed fields as per your application's requirements.