Blog
Sample Form Processing with Email Validation in PHP
Posted on June 18, 2015 in PHP by Matt Jennings
<?php
session_start();
$errors = array();
// If statement checks if some text has been submitted as an email and isn't null
if(isset($_POST['email']) && $_POST['email'] != NULL)
{
// If statement below checks in a submitted email is a valid email
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
array_push($errors, 'This email is not valid');
}
}
else
{
array_push($errors, 'Email should not be empty');
}
if(!empty($errors))
{
$_SESSION['errors'] = $errors;
header('Location: notes.php');
}
else
{
echo '<h2>You are logged in!</h2>';
}
?>
Leave a Reply