diff --git a/functions.php b/functions.php index cd1cc4c..0eb2dd7 100644 --- a/functions.php +++ b/functions.php @@ -35,6 +35,13 @@ function validateEmail($email) */ function sanitizeInput($input) { + // Handle non-string values + if (is_array($input)) { + return array_map('sanitizeInput', $input); + } + if (!is_string($input)) { + $input = (string)$input; + } return htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8'); } @@ -422,7 +429,16 @@ function redirect($url) */ function post($key, $default = '') { - return isset($_POST[$key]) ? sanitizeInput($_POST[$key]) : $default; + if (!isset($_POST[$key])) { + return $default; + } + + // If the value is an array, return the first element or default + if (is_array($_POST[$key])) { + return !empty($_POST[$key]) ? sanitizeInput($_POST[$key][0]) : $default; + } + + return sanitizeInput($_POST[$key]); } /**