SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: validation

  1. #1
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face 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 .

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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;
    }
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks , worked perfectly

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    @felgall

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

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    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;
    }
    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

  6. #6
    SitePoint Enthusiast rgf207's Avatar
    Join Date
    Feb 2006
    Location
    Maryland
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by minusten View Post
    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

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,299
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by minusten View Post
    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
    That's because the code says "exit":

    Code:
    header("Location: Contact.html");
    exit;
    }
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •