Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-22-2004, 11:14 PM   PM User | #1
ryno267
New Coder

 
Join Date: Dec 2002
Location: earth, usa, az
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
ryno267 is an unknown quantity at this point
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";
   }
}
?>
ryno267 is offline   Reply With Quote
Old 03-22-2004, 11:29 PM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
I believe there's a tutorial on www.zend.com which does check to see if the domain/email exists.
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 03-25-2004, 03:31 PM   PM User | #3
Serex
Regular Coder

 
Join Date: Mar 2004
Location: Australia
Posts: 217
Thanks: 0
Thanked 1 Time in 1 Post
Serex is an unknown quantity at this point
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.");
}
Serex is offline   Reply With Quote
Old 03-25-2004, 04:17 PM   PM User | #4
ryno267
New Coder

 
Join Date: Dec 2002
Location: earth, usa, az
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
ryno267 is an unknown quantity at this point
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.
__________________
rYnoweb

Last edited by ryno267; 03-25-2004 at 04:22 PM..
ryno267 is offline   Reply With Quote
Old 03-26-2004, 12:35 AM   PM User | #5
DHTML Kitchen
Regular Coder

 
Join Date: Mar 2004
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
DHTML Kitchen is an unknown quantity at this point
Here:

http://www.zend.com/zend/spotlight/ev12apr.php
__________________
http://dhtmlkitchen.com/
DHTML Kitchen is offline   Reply With Quote
Old 03-26-2004, 01:17 AM   PM User | #6
ryno267
New Coder

 
Join Date: Dec 2002
Location: earth, usa, az
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
ryno267 is an unknown quantity at this point
nice...
that one works for me...

thanks
__________________
rYnoweb
ryno267 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:36 PM.


Advertisement
Log in to turn off these ads.