Validation

hello all,

i have this simple code

elseif($_POST[“Email”] == “” || $_POST[“Email”] ==“Enter your Email address”)
{
header(“Location: Contact.html”);
exit;
}

can anyone help me with getting it to validate whether it has an @ and a .

To properly validate that it is a properly formatted email address use:

if (!filter_var($_POST[‘email’],FILTER_VALIDATE_EMAIL))
{
header(“Location: Contact.html”);
exit;
}

Thanks , worked perfectly

@felgall

Interesting. How does that stack up in comparison with a more detailed preg_match check?

Hi

just looking at this again

when i input isnt valid the browser window just goes plain white the url says its the same page instead of redisplaying the form again

do you have an error_log file in your directory that you can view? That may tell you what’s happening

That’s because the code says “exit”:

header("Location: Contact.html");
[COLOR="#FF0000"]exit;[/COLOR]
}

The server is told to display the Contact.html page but not any of its content. So you could remove “exit” and that should let the page display again with the form and all. Or you could display a message etc. to inform the user of what went wrong, which is normally what you’d do.