Closed Thread
Results 1 to 3 of 3




  

Thread: Email validation

      
  1. #1
    I'm New! prometheus is on a distinguished road
    Join Date
    August 19, 2007
    Posts
    3
    Rep Power
    0
    Feedback Score
    0

    Default Email validation

    Hi all, I'm trying to add email validation to a form but don't exactly know where to put it. I would like to add the code found HERE but don't know where it should go on the page. What I have right now is
    Code:
    <?
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    $_POST['firstname']=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $_POST['firstname']);if($_POST['firstname']=="" || $_POST['lastname']=="" || $_POST['email']=="" || $_POST['comments']=="" ){
    $errors=1;
    $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
    }
    if($errors==1) $msg.="You did not enter one or more of the required fields.<br />Please go back and re-enter your contact request.";
    else{
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$_SERVER['HTTP_HOST'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
    $message="
    Firstname: ".$_POST['firstname']."
    Lastname: ".$_POST['lastname']."
    Email: ".$_POST['email']."
    Address: ".$_POST['address']."
    City: ".$_POST['city']."
    State: ".$_POST['state']."
    Zip: ".$_POST['zip']."
    Phone: ".$_POST['phone']."
    Interested: ".$_POST['interested']." 
    Comments: ".$_POST['comments']."
    ";
    mail("someone@somewhere.com","Stuff",$message,"From: Web Form");f
    mail("$email","Thank you for contacting us", "Hi $firstname,\n
    Thank you for contacting us!\n
    We will respond to your enquiry as soon as possible.\n\n\n
    Thanks.; 
    $msg.="Thank you!<br />Your enquiry has been submitted and we will respond as soon as we can.";
    }
    ?>
    Thanks.

  2. #2
    I'm New! bgillingham will become famous soon enoughbgillingham will become famous soon enough bgillingham's Avatar
    Join Date
    October 6, 2007
    Posts
    37
    Rep Power
    5
    Feedback Score
    0

    Default

    You could add a function to check basically the syntax of the entered email address.

    By the way, if you or your host plans to upgrade to php5, you better change all instances of the loose php tag "<?" to the proper php tag "<?php" or your page will die when php5 is running.

    In your code, add the red lines:
    Code:
    <?
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    $_POST['firstname']=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $_POST['firstname']);if($_POST['firstname']=="" || $_POST['lastname']=="" || $_POST['email']=="" || $_POST['comments']=="" ){
      $errors=1;
      $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
    }
    if (!is_valid_email($_POST['email'])) {
      $errors=1;
      $error.="<li>Your email address does not appear to be valid. Please go back and try again.";
    }
    Now, you can just add this before the end of the php: (the line before the "?>")
    Code:
    function is_valid_email($email) { 
      if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $email))
        return 0;
      else 
        return 1;
    }

  3. #3
    I'm New! prometheus is on a distinguished road
    Join Date
    August 19, 2007
    Posts
    3
    Rep Power
    0
    Feedback Score
    0

    Default

    Thanks so much for the help, and I appreciate the heads-up with regards to the php tag, that would have been very problematic.

Closed Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Validation
    By CoxysBlog in forum HTML & Website Design
    Replies: 10
    Last Post: Apr 23rd, 2008, 6:04 pm
  2. Validation & Websites
    By nanobi in forum General Business
    Replies: 23
    Last Post: Mar 17th, 2007, 6:11 pm

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
WebTalkForums
WebTalkForums
Recent Forum Threads