Hi Everyone,
I am trying to test a simple email validation form using $_SERVER at the same page as
<?php
if (isset($_POST['submitted'])) {
$email = $_POST['email'];
$result = filter_var($email, FILTER_VALIDATE_EMAIL) ;
if($result)
{
echo "Valid email address.";
}
else {
echo "Invalid email address.";
}
}
?>
<html>
<body>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
<p>E-mail: <input type="text" name="email" /></p>
<p><input type="submit" name="submitted" value="Validate Email"></p>
</form>
</body>
</html>
Now the validaion part works fine and PHP validate the user input but when I refresh the page the last validation result still remains in the page!
I tried to fix the issue by adding following after the echo functions
header("Location: ".$_SERVER['PHP_SELF']);
which refresh the page but this time I am not getting the results of validations.
Can you please let me know how I can fix the issue?
Thanks for your time in advance.