Go Back   CodingForums.com > :: Client side development > JavaScript programming

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 07-31-2008, 06:19 AM   PM User | #1
e1$ki
New to the CF scene

 
Join Date: Jul 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
e1$ki is an unknown quantity at this point
Smile email address validation - won't pop up box

Hi People,

I am not a veteran coder so this may be really obvious when I post that I can't get this to work. The page is at http://www.ewanski-gbc.com/contact2.php

and here is my code:

Code:
<?php include 'head1.php'; ?>
<title>Ewanski Green Building Consulting - Contact Us</title>
<script type="text/javascript">
<!--

function validate_form ( )
{
    valid = true;
    if(document.theform.fullname.value == ""){
			alert ( "Please fill in your full name." );
    	valid = false;
    }
		if(document.theform.email.value == ""){
			alert ( "Please fill in your email address." );
			valid = false;
    }
		if(Verify_Email_Address(document.theform.email.value)){
			alert ( "Please enter a valid email address.");
			valid = false;
		}
		if(document.theform.message.value == ""){
			alert ( "Please fill in a message." );
			valid = false;
    }
    return valid;
}

function Verify_Email_Address($email_address)
{
     
		 //Assumes that valid email addresses consist of user_name@domain.tld
     $at = strrpos($email_address, "@");
     $dot = strrpos($email_address, ".");
		alert ("at = " . $at);
     if($at == false ||
        $dot == false ||
        $dot <= $at + 1 ||
        $dot == 0 ||
        $dot == strlen($email_address) - 1)
        return(false);

     $user_name = substr($email_address, 0, $at);
     $domain_name = substr($email_address, $at + 1, strlen($email_address));

     if(Validate_String($user_name) === false ||
        Validate_String($domain_name) === false)
      return(false);

     return(true);
}
//-->
</script>
<?php include 'head2.php'; ?>

<div id="page">
	<div id="content">
		<div>
			<h2 class="title">Contact Us</h2>
			<p>If you have questions, feedback, or an interest in our services, please don't hesitate to contact us. We would love to hear from you!</p>
			<p>Please contact us using the online web form below.</p>

		 	<form method="post" action="formtoemail.php" name="theform" onsubmit="return validate_form ( );">
		  <table border="0" width="100%">
				<tr>
				<td>Full Name:</td>
				<td><input type="text" name="fullname" size="40" maxlength=""></td>
				</tr>

				<tr>
				<td>Email Address:</td>
				<td><input type="text" name="email" size="40" maxlength=""></td>
				</tr>

				<tr>
				<td>How We May Help You:</td>
				<td><textarea name="message" rows="10" cols="50"></textarea></td>
				</tr>
				
        <tr>
				<td></td>
				<td><input type="submit" value="Send">
        <input type="reset" value="Clear"></td>
			
			</table>
    	</form>
		</div>
</div>



<?php include 'footer.php'; ?>
I am confused. I just want it to validate that there is a real email in there. I checked the javascript console in Firefox and it said that strrpos wasn't valid but I looked it up at php.net and it's in there. So, I don't know where to look next.

Thanks in advance,
Patricia
e1$ki is offline   Reply With Quote
Old 07-31-2008, 07:12 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Why do you not simplify things and cut out the clumsy email verification function. Replace:-

Code:
if(document.theform.email.value == "") {
alert ( "Please fill in your email address." );
valid = false;
}
if(Verify_Email_Address(document.theform.email.value)){
alert ( "Please enter a valid email address.");
valid = false;
} 
By:-

Code:
var em = document.theform.email.value;
if (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(em))) { 
alert ( "Please fill in a valid email address." );
valid = false;
}


BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.
Philip M is offline   Reply With Quote
Old 07-31-2008, 07:24 AM   PM User | #3
e1$ki
New to the CF scene

 
Join Date: Jul 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
e1$ki is an unknown quantity at this point
Philip,

Thank you! the code works! Much simpler. And it works.

Yes, you have a good point about the "thanks in advance" thing. I didn't mean for it to sound snotty but I think you are right. It does sound pretty bad. Thanks for taking the time to let me know.

Best,
Patricia
e1$ki is offline   Reply With Quote
Old 07-31-2008, 07:29 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Patricia -

Glad it works and welcome to the forum!

Don't take my comments about "thanks in advance" too seriously. But the fact is 98% of people who use that gruesome expression are newcomers to the forum.

Best wishes,

Philip M
Philip M 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 01:22 AM.


Advertisement
Log in to turn off these ads.