Results 1 to 2 of 2

Thread: Contact form tutorial validation

  1. #1
    12
    posts
    Registered User

    Contact form tutorial validation

    First of all contact form tutorial is really nice, but I have a couple of questions. The tutorial assumes that if you've pressed submit button your information is good to go. I would like to validate a couple of fields (for example name and email) if they're not set you would get an error message (i.e you forget to enter a valid e-mail) and link back to the previous page. So any information isn't sent before certain fields are filled correctly.

    I would like to use PHP for this because not everyone has their Javascript turned on an it's more secure to check your information serverside, not user agent side.

    Any help would be really appriciated,

    Thanks in advance!

  2. #2
    Quote Originally Posted by nasu
    First of all contact form tutorial is really nice, but I have a couple of questions. The tutorial assumes that if you've pressed submit button your information is good to go. I would like to validate a couple of fields (for example name and email) if they're not set you would get an error message (i.e you forget to enter a valid e-mail) and link back to the previous page. So any information isn't sent before certain fields are filled correctly.

    I would like to use PHP for this because not everyone has their Javascript turned on an it's more secure to check your information serverside, not user agent side.

    Any help would be really appriciated,

    Thanks in advance!
    PHP Code:
     <?php 
    if(empty($_POST['field'])) {
    echo 
    "Not filled in a field, you will now be transferred back";
    header("Location: back.php");
    }
    if(empty(
    $_POST['field2'])) {
    echo 
    "Not filled in a field, you will now be transferred back";
    header("Location: back.php");
    }
    if(!
    ValidateEmail($email)) { 
    echo 
    "email is not valid\n"
    header("Location: back.php");
    }
    else {
    do 
    stuff cos they passed
    }
    function 
    ValidateEmail($email) { 
    if (
    eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$"$email)) 

       return 
    true

    else { 
    return 
    false


    ?>
    hope this helps

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012