PHP: Form email validation

This entry is part 52 of 54 in the series PHP Tutorial

We combine the simple form that we have worked on with the email validation method we have discussed earlier in the previous post.

<html>
<body>

<form action="" method="post">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit" name="submit">
</form>

</body>
</html>


<html>
<body>

<?php
$your_name = $_POST["name"];
$your_email = $_POST["email"];

if (isset($_POST['submit'])) {
    echo "Welcome " . $your_name . "<br>";
    if (filter_var($your_email, FILTER_VALIDATE_EMAIL)) {
        echo "Your Email is " . $your_email;
    } else {
        echo "This ($your_email) email address is considered invalid.";
    }
}
?>
</body>
</html>

You can try the code here

Series Navigation<< PHP: Email validation
PHP: URL validation >>