Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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