Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2002
    Location
    earth, usa, az
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form email validation

    How do I integrate an email validator into this form?
    I've seen snippets from some other code, but what i've tried hasn't worked yet.
    Basically want to validate an actual email.
    Simple would be to make sure the @ and .com/.net etc is there, but there is some better ones that check the domain status and stuff.
    Any ideas?

    Code:
    PHP Code:
    <?
    $form_block 
    "
    <form method=\"POST\" action=\"$_SERVER[PHP_SELF]\">
    <p><strong>Your name:</strong><br />
    <input type=\"text\" name=\"sender_name\" value=\"$_POST[sender_name]\" size=30></p>
    <p><strong>Your E-Mail Address:</strong><br />
    <input type=\"text\" name=\"sender_email\" value=\"$_POST[sender_email]\" size=30></p>
    <p><strong>Message:</strong><br />
    <textarea name=\"message\" cols=30 rows=5 wrap=virtual>$_POST[message]</textarea></p>
    <input type=\"hidden\" name=\"op\" value=\"ds\">
    <p><input type=\"submit\" name=\"submit\" value=\"Send This Form\"></p>
    </form>"
    ;

    if (
    $_POST[op] != "ds") {
       
    // show form
       
    echo "$form_block";
    } else if (
    $_POST[op] == "ds") {
       
    // check value of $_POST[sender_name]
       
    if ($_POST[sender_name] == "") {
       
    $name_err "<div class=\"error\" align=\"center\">The Name field was left Blank</div><br />";
       
    $send "no";
       }
       
    // check value of $_POST[sender_email]
       
    if ($_POST[sender_email] == "") {
       
    $email_err "<div class=\"error\" align=\"center\">The Email field was left Blank</div><br />";
       
    $send "no";
       }
       
    // check value of $_POST[message]
       
    if ($_POST[message]== "") {
       
    $message_err "<div class=\"error\" align=\"center\">You did not enter a Message</div><br />";
       
    $send "no";
       }
       if (
    $send != "no") {
       
    // it's ok to send, so construct the mail
       
    $msg "E-MAIL SENT FROM WWW SITE\n";  //  body text build
       
    $msg .= "Sender's name:    $_POST[sender_name]\n";
       
    $msg .= "Sender's E-Mail:  $_POST[sender_email]\n";
       
    $msg .= "Message:          $_POST[message]\n\n";

       
    $to "sales@mydomain.com";
       
    $subject "Contact Form";
       
    $mailheaders "From: $_POST[sender_email]\n";
       
    $mailheaders .= "Reply-To: $_POST[sender_email]\n\n";
       
    // send the mail
       
    mail($to$subject$msg$mailheaders);
       
    // display confirmation to user
       
    echo "<p>Thank you $_POST[sender_name], your content has been sent!><br />
       A member of our staff will be in contact with you as soon as possible.</p>"
    ;
       } else if (
    $send == "no") {
       
    // print error messages
       
    echo "$name_err";
       echo 
    "$email_err";
       echo 
    "$message_err";
       echo 
    "$form_block";
       }
    }
    ?>

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I believe there's a tutorial on www.zend.com which does check to see if the domain/email exists.

  • #3
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    you could do a quick one using javascript

    Code:
    var txtEmail = document.forms.frmName.txtEmail.value; // assign the value of the text box to txtEmail
    
    if (txtEmail.indexOf("@") == -1 || txtEmail.indexOf(".") == -1) // check to see if email is 'valid'
    {
        alert("Sorry but you have entered an incorrect email address. Please try again.");
    }

  • #4
    New Coder
    Join Date
    Dec 2002
    Location
    earth, usa, az
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I know ... but if i was to do that I'd use the behavior "form validation" in dreamweaver.

    I'd like to incorporate it into the php functions so that i could have div tags appear under or next to the input box with the error.
    Last edited by ryno267; 03-25-2004 at 05:22 PM.

  • #5
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #6
    New Coder
    Join Date
    Dec 2002
    Location
    earth, usa, az
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nice...
    that one works for me...

    thanks


  •  

    Posting Permissions

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