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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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


  •  

    Posting Permissions

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