diff --git a/functions/requests.php b/functions/requests.php index 0340fb4..ac4cbc4 100644 --- a/functions/requests.php +++ b/functions/requests.php @@ -113,6 +113,25 @@ function postInt(string $name) : int { return (int)$_POST[$name]; } +/** + * Get an email address specified in a $_POST request + * + * @param string $name The name of the post field containing the + * email address + * @return string The email address + */ +function postEmail(string $name) : string { + + //Get the email as a string + $email = postString($name, 5); + + //Check the email + if(!filter_var($email, FILTER_VALIDATE_EMAIL)) + Rest_fatal_error(400, "Specified email address is invalid !"); + + return $email; +} + /** * Securely transform user given number (mixed) to integer (int) *