sessionValMessages (function)

Last updated: Tue, Oct 31, 2023 2:31 pm
Return to Knowledgebase

Purpose

Manage and store various types of messages in the session.

Location

users/helpers/us_helpers.php

Parameters

# Parameter Data Type Required Description
1 $valErr = [] array Yes Array of validation error messages
2 $valSuc = [] array Yes Array of validation success messages
3 $genMsg = [] array Yes Array of general messages

Returns

Data Type Description of Returned Data
nothing

Further Documentation:

What It Does:
Allows you to pass 3 parameters from standard PHP arrays to the $_SESSION variables without having to deal with the crazy naming.
Note that the session variables have these crazy names to prevent cross talk on shared hosting environments.

How it works:
1. Checks if the session for the specified message type is set and is an array. If it is, and the corresponding message array is not empty and not null, it appends the new message to the existing messages in the session.
2. If the session is set and not empty, and the corresponding message array is not empty and not null, it saves the existing session message, empties the session for that message type, and then appends the new message to the empty session.
3. If the provided message array is not empty and not null, it sets the session message directly to the provided message.


// Example: Storing validation error messages in the session
$valErr = ["Error 1", "Error 2"];
sessionValMessages($valErr);