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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Form Validator

  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Form Validator

    So far, my for validator works, but when I want to see if it works for when a user leaves the message area blank, my form just sends the email anyway. Also, I am not too sure how to go about validating my my captcha code.



    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript">
    function ValidateContactForm()
    {
         var name = document.ContactForm.name;
        var email = document.ContactForm.email;
        var text = document.ContactForm.text;
    
        if (name.value == "")
        {
            window.alert("Please enter your name.");
            name.focus();
            return false;
        }
        
        if (email.value == "")
        {
            window.alert("Please enter a valid e-mail address.");
            email.focus();
            return false;
        }
        if (email.value.indexOf("@", 0) < 0)
        {
            window.alert("Please enter a valid e-mail address.");
            email.focus();
            return false;
        }
        if (comment.value == "")
        {
            window.alert("Please provide a detailed description or comment.");
            text.focus();
            return false;
        }
        return true;
    }
    </script>
    </head>
    <body>
    
    <div id="templatemo_wrapper"> 
    
    	<div id="templatemo_header">
    
     
            
            <ul id="social_box">
                        <li><a href="http://www.facebook.com/"><img src="images/facebook.png" alt="facebook" /></a></li>
                <li><a href="http://www.twitter.com/"><img src="images/twitter.png" alt="twitter" /></a></li>              
            </ul>
            
          	<div id="site_title">
                <h1><a href="index.htm"><img src="images/logo2.png" alt="logo" /><span></span></a></h1>
            </div> <!-- end of site_title -->
            
          
        </div> <!-- end of templatemo_header -->
        
    <div id="templatemo_menu">
        	<div class="home"><a href="index.htm"></a></div>
            <ul>
              <li><a href="index.htm"><span>Home</span></a></li>
                <li><a href="test.htm"><span>Test</span></a></li>
                <li><a href="examples.htm"><span>Examples</span></a></li>
                <li><a href="Questions.htm"><span>Questions</span></a></li>
    	    <li><a href="contact.htm"><span>Contact</span></a></li>
                <li><a href="comments.htm">Have A Comment?<span>Comments</span></a></li>
            </ul>    	
        </div> 
    
    <!-- end of templatemo_menu -->
        
        <div id="templatemo_content_wrapper">
        	<div id="templatemo_content_top"></div>
            <div id="templatemo_content">
            
                <h2>Contact</h2>
    
    
    
    <p><b>E-mail: starr05@gmail.com </b></p>
    
    <p><b><a href="http://www.twitter.com/">Twitter</a></b></p>
            
                <div class="cleaner_h50"></div>
                
                	<div id="contact_form">
                
                        <h4>Quick Contact</h4>
                        
                        <form method="post" name="ContactForm" id="contact" action="email.php" onsubmit="return ValidateContactForm();">
                            
                            <div class="col_w340 float_l">
                            
                                <label for="name">Name (* Required):</label> <input name="name" type="text" class="input_field" id="author" maxlength="40" />
                              	<div class="cleaner_h10"></div>
    
     <label for="subject">Subject:</label> <input name="subject" type="text" class="input_field" id="subject" maxlength="40" />
                              	<div class="cleaner_h10"></div>
    
                                
                                <label for="email">Email (* Required):</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" />
                              	<div class="cleaner_h10"></div>
                                
                                
    Type verification image:<br />
    <input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"/>
    <img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" /><br />
    <br />                        
    
    </div>
                            
    
    
                            <div class="col_w340 float_r">
                            
                                <label for="text">Message (*Required):</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
                                <div class="cleaner_h10"></div>
                                
                                <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" />
                                <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" />
                                
                            </div>
                            
                       </form>
    
                </div> 
    
                <div class="cleaner"></div>
                
            </div>
            <div id="templatemo_content_bottom"></div>
    	</div>
        
        <div id="templatemo_sp_box">
        
        	<div class="col_w340 float_l">
             
    			</div>
            </div>
            
            <div class="col_w340 float_r">
            
    			</div>
            </div>
        
        </div>
        
        <div id="templatemo_footer">
    
          
            Copyright © 2011 <a href="www.twitter.com/">Starr</a><br/> 
            <a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a> 
            by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a>
        
        </div> <!-- end of templatemo_footer -->
        
    </div> <!-- end of templatemo_wrapper -->    
    
    </body>
    </html>

    PHP Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>


    <?php


    $first_name
    =$_POST['name'];
    $email_address=$_POST['email'];
    $subject=$_POST['subject'];
    $message=$_POST['text'];

    mail("starr05@gmail.com","Vadhir Derbez Photography: $subject",
    $message"From: $first_name <$email_address>");

    echo 
    "Thank you for using our mail form.<br/>";
    echo 
    "Your email has been sent.";
    ?>




    </body>
    </html>

    PHP Code:

    <?php


    header
    ('Content-type: image/jpeg');

    $width 50;
    $height 24;

    $my_image imagecreatetruecolor($width$height);

    imagefill($my_image000xFFFFFF);

    // add noise
    for ($c 0$c 40$c++){
        
    $x rand(0,$width-1);
        
    $y rand(0,$height-1);
        
    imagesetpixel($my_image$x$y0x000000);
        }

    $x rand(1,10);
    $y rand(1,10);

    $rand_string rand(1000,9999);
    imagestring($my_image5$x$y$rand_string0x000000);

    setcookie('tntcon',(md5($rand_string).'a4xn'));

    imagejpeg($my_image);
    imagedestroy($my_image);
    ?>

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    It would be easy to answer this, but you're asking a question that the error console must be answering.

    Always start there.

  • #3
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,338
    Thanks
    29
    Thanked 282 Times in 276 Posts
    Quote Originally Posted by saxchick1 View Post
    but when I want to see if it works for when a user leaves the message area blank, my form just sends the email anyway.
    comment.value presumably refers to an element with name="comment" which, as far as I can tell, doesn't exist. Perhaps you meant to use something like:

    Code:
    if (document.getElementById("text").value === "") {
    	window.alert("Please provide a detailed description or comment.");
    	document.getElementById("text").focus();
    	return false;
    }
    (It's bad practice to reference element names as property names, so I used getElementById to reference your elements by their IDs instead.)
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,140
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Form validation of the pattern if (document.getElementById("text").value === "") { is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. Suggest you make it that at least 6 alpha characters are required in a comment field to pass the validation.

    The same applies to email addresses - if (email.value.indexOf("@", 0) < 0) is totally inadequate validation.
    This subject has been covered a zillion times in this forum.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Feb 2009
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Logic Ali View Post
    It would be easy to answer this, but you're asking a question that the error console must be answering.

    Always start there.
    When I tested it, I didnt get an error in the error console.

  • #6
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by saxchick1 View Post
    When I tested it, I didnt get an error in the error console.
    You assign to comment.value but nowhere is there defined a variable or even an ID with that name. That must (and does) generate an error.

  • #7
    New Coder
    Join Date
    Feb 2009
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I went back and made some changes to my form and saw a few examples on here on how validate an email address. Now, when I test it, the only error I get is "Expected '(' Line: 17 Char: 1. Before that I had the return statement outside of function, I moved my return statement from where I validated the comment area outside and it worked, but it seems now I have more errors than I expected.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript">
    function ValidateContactForm()
    {
    if (document.getElementById("author").value === "") 
    {
    	window.alert("Please provide a detailed description or comment.");
    	document.getElementById("author").focus();
    	}
    if 
    {
    ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(document.form2.
    
    email.value)) { 
    alert ("Invalid email address!  Please retry.");
    document.ContactForm.email.value == "";  // clear the field
    document.ContactForm.email.focus();  // and refocus on it
    return false;
    }
    if (document.getElementById("text").value === "") 
    {
    	window.alert("Please provide a detailed description or comment.");
    	document.getElementById("text").focus();
    	}
    return false;
    }
    }
    </script>
    </head>
    <body>
    
    <div id="templatemo_wrapper"> 
    
    	<div id="templatemo_header">
    
     
            
            <ul id="social_box">
                        <li><a href="http://www.facebook.com/"><img 
    
    src="images/facebook.png" alt="facebook" /></a></li>
                <li><a href="http://www.twitter.com/"><img src="images/twitter.png" 
    
    alt="twitter" /></a></li>              
            </ul>
            
          	<div id="site_title">
                <h1><a href="index.htm"><img src="images/logo2.png" alt="logo" 
    
    /><span></span></a></h1>
            </div> <!-- end of site_title -->
            
          
        </div> <!-- end of templatemo_header -->
        
    
    
    <!-- end of templatemo_menu -->
        
        <div id="templatemo_content_wrapper">
        	<div id="templatemo_content_top"></div>
            <div id="templatemo_content">
            
                <h2>Contact</h2>
    
    
    
    <p><b>E-mail: starr05@gmail.com </b></p>
    
    <p><b><a href="http://www.twitter.com/">Twitter</a></b></p>
            
                <div class="cleaner_h50"></div>
                
                	<div id="contact_form">
                
                        <h4>Quick Contact</h4>
                        
                        <form method="post" name="ContactForm" id="contact" action="email.php" 
    
    onsubmit="return ValidateContactForm();">
                            
                            <div class="col_w340 float_l">
                            
                                <label for="author">Name (* Required):</label> <input 
    
    name="author" type="text" class="input_field" id="author" maxlength="40" />
                              	<div class="cleaner_h10"></div>
    
     <label for="subject">Subject:</label> <input name="subject" type="text" class="input_field" 
    
    id="subject" maxlength="40" />
                              	<div class="cleaner_h10"></div>
    
                                
                                <label for="email">Email (* Required):</label> <input 
    
    name="email" type="text" class="input_field" id="email" maxlength="40" />
                              	<div class="cleaner_h10"></div>
                                
                                
    Type verification image:<br />
    <input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid 
    
    #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; 
    
    font-size:11px;"/>
    <img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it 
    
    in the box" width="50" height="24" align="absbottom" /><br />
    <br />                        
    
    </div>
                            
    
    
                            <div class="col_w340 float_r">
                            
                                <label for="text">Message (*Required):</label> <textarea 
    
    id="text" name="text" rows="0" cols="0" class="required"></textarea>
                                <div class="cleaner_h10"></div>
                                
                                <input type="submit" class="submit_btn float_l" name="submit" 
    
    id="submit" value="Send" />
                                <input type="reset" class="submit_btn float_r" name="reset" 
    
    id="reset" value="Reset" />
                                
                            </div>
                            
                       </form>
    
                </div> 
    
                <div class="cleaner"></div>
                
            </div>
            <div id="templatemo_content_bottom"></div>
    	</div>
        
        <div id="templatemo_sp_box">
        
        	<div class="col_w340 float_l">
             
    			</div>
            </div>
            
            <div class="col_w340 float_r">
            
    			</div>
            </div>
        
        </div>
        
        <div id="templatemo_footer">
    
          
            Copyright © 2011 <a href="www.twitter.com/">Starr</a><br/> 
            <a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a> 
            by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a>
        
        </div> <!-- end of templatemo_footer -->
        
    </div> <!-- end of templatemo_wrapper -->    
    
    </body>
    </html>

  • #8
    New Coder
    Join Date
    Feb 2009
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think I am on the right track now. My error console says (Expected ')' Line:28 Char:52), did I leave a ) out? Also, when I test it, the alert box shows up, but when I click ok, the message gets sent to the email address. Not too sure what I did and I am also not too sure if I validated the email address right.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript">
    function ValidateContactForm()
    {
    if (document.getElementById("text").value === "") 
    {
    	window.alert("Please provide a detailed description or comment.");
    	document.getElementById("text").focus();
    	}
    if (document.getElementById("author").value === "")
    {
    	window.alert("Please provide your name.");
    	document.getElementById("author").focus();
    }
    if (document.getElementById("verif_box").value === "")
    {
    	window.alert("Please enter captcha code.");
    	document.getElementById("verif_box").focus();
    }
    
    if 
    
    (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(emailAddress.val
    
    ue))) {
    	window.alert("Please enter a valid email address.");
    	document.getElementById("email").focus();
    }
    return false;
    }
    
    </script>
    </head>
    <body>
    
    <div id="templatemo_wrapper"> 
    
    	<div id="templatemo_header">
    
     
            
            <ul id="social_box">
                        <li><a href="http://www.facebook.com/"><img 
    
    src="images/facebook.png" alt="facebook" /></a></li>
                <li><a href="http://www.twitter.com/"><img src="images/twitter.png" 
    
    alt="twitter" /></a></li>              
            </ul>
            
          	<div id="site_title">
                <h1><a href="index.htm"><img src="images/logo2.png" alt="logo" 
    
    /><span></span></a></h1>
            </div> <!-- end of site_title -->
            
          
        </div> <!-- end of templatemo_header -->
        
    
    
    <!-- end of templatemo_menu -->
        
        <div id="templatemo_content_wrapper">
        	<div id="templatemo_content_top"></div>
            <div id="templatemo_content">
            
                <h2>Contact</h2>
    
    
    
    <p><b>E-mail: starr05@gmail.com </b></p>
    
    <p><b><a href="http://www.twitter.com/">Twitter</a></b></p>
            
                <div class="cleaner_h50"></div>
                
                	<div id="contact_form">
                
                        <h4>Quick Contact</h4>
                        
                        <form method="post" name="ContactForm" id="contact" action="email.php" 
    
    onsubmit="return ValidateContactForm();">
                            
                            <div class="col_w340 float_l">
                            
                                <label for="author">Name (* Required):</label> <input 
    
    name="author" type="text" class="input_field" id="author" maxlength="40" />
                              	<div class="cleaner_h10"></div>
    
     <label for="subject">Subject:</label> <input name="subject" type="text" class="input_field" 
    
    id="subject" maxlength="40" />
                              	<div class="cleaner_h10"></div>
    
                                
                                <label for="email">Email (* Required):</label> <input 
    
    name="email" type="text" class="input_field" id="email" maxlength="40" />
                              	<div class="cleaner_h10"></div>
                                
                                
    Type verification image:<br />
    <input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid 
    
    #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; 
    
    font-size:11px;"/>
    <img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it 
    
    in the box" width="50" height="24" align="absbottom" /><br />
    <br />                        
    
    </div>
                            
    
    
                            <div class="col_w340 float_r">
                            
                                <label for="text">Message (*Required):</label> <textarea 
    
    id="text" name="text" rows="0" cols="0" class="required"></textarea>
                                <div class="cleaner_h10"></div>
                                
                                <input type="submit" class="submit_btn float_l" name="submit" 
    
    id="submit" value="Send" />
                                <input type="reset" class="submit_btn float_r" name="reset" 
    
    id="reset" value="Reset" />
                                
                            </div>
                            
                       </form>
    
                </div> 
    
                <div class="cleaner"></div>
                
            </div>
            <div id="templatemo_content_bottom"></div>
    	</div>
        
        <div id="templatemo_sp_box">
        
        	<div class="col_w340 float_l">
             
    			</div>
            </div>
            
            <div class="col_w340 float_r">
            
    			</div>
            </div>
        
        </div>
        
        <div id="templatemo_footer">
    
          
            Copyright © 2011 <a href="www.twitter.com/">Starr</a><br/> 
            <a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a> 
            by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a>
        
        </div> <!-- end of templatemo_footer -->
        
    </div> <!-- end of templatemo_wrapper -->    
    
    </body>
    </html>
    Last edited by saxchick1; 09-08-2011 at 02:38 AM.

  • #9
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,338
    Thanks
    29
    Thanked 282 Times in 276 Posts
    Quote Originally Posted by saxchick1 View Post
    My error console says (Expected ')' Line:28 Char:52), did I leave a ) out?
    I can't test your document directly as an XHTML document because your source code has PHP code in it that causes it to not be well-formed XML.

    In the provided code, line 28 only has one to two characters (line-breaking characters), so I'm not sure what that error message means.

    I suspect that the error is within these three lines of code (lines 31 through 33):

    Code:
    (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(emailAddress.val
    
    ue))) {
    Note that, in the above code, an if statement's condition is broken over three lines. The first break comes in the middle of a property name (i.e., value).
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #10
    New Coder
    Join Date
    Feb 2009
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arbitrator View Post
    I can't test your document directly as an XHTML document because your source code has PHP code in it that causes it to not be well-formed XML.

    In the provided code, line 28 only has one to two characters (line-breaking characters), so I'm not sure what that error message means.

    I suspect that the error is within these three lines of code (lines 31 through 33):

    Code:
    (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(emailAddress.val
    
    ue))) {
    Note that, in the above code, an if statement's condition is broken over three lines. The first break comes in the middle of a property name (i.e., value).
    I went back and changed things in my script, but still getting errors (Expected ')' Line:13 Char:125)

    } else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a- - This is line 13.

    Also, I think I may have two different ways of calling the 'name' textbox, in my php I have it as name, and in my form I have it as 'author'

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript">
    function ValidateContactForm() {
      if (document.getElementById("author").value === "") {
        window.alert("Please provide a detailed description or comment.");
        document.getElementById("author").focus();
      } else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(document.ContactForm.email.value)) { 
        alert ("Invalid email address!  Please retry.");
        document.ContactForm.email.value == "";  // clear the field
        document.ContactForm.email.focus();  // and refocus on it
      } else if (document.getElementById("text").value === "") {
        window.alert("Please provide a detailed description or comment.");
        document.getElementById("text").focus();
      } else {    
        return true; // successful
      }
      return false; // failed validation
    }
    
    </script>
    </head>
    <body>
    
    <div id="templatemo_wrapper"> 
    
    	<div id="templatemo_header">
    
     
            
            <ul id="social_box">
                        <li><a href="http://www.facebook.com/"><img src="images/facebook.png" alt="facebook" /></a></li>
                <li><a href="http://www.twitter.com/"><img src="images/twitter.png" alt="twitter" /></a></li>              
            </ul>
            
          	<div id="site_title">
                <h1><a href="index.htm"><img src="images/logo2.png" alt="logo" /><span></span></a></h1>
            </div> <!-- end of site_title -->
            
          
        </div> <!-- end of templatemo_header -->
        
    <span>Comments</span></a></li>
            </ul>    	
        </div> 
    
    <!-- end of templatemo_menu -->
        
        <div id="templatemo_content_wrapper">
        	<div id="templatemo_content_top"></div>
            <div id="templatemo_content">
            
                <h2>Contact</h2>
    
    
    
    <p><b>E-mail: starr05@gmail.com </b></p>
    
    <p><b><a href="http://www.twitter.com/">Twitter</a></b></p>
            
                <div class="cleaner_h50"></div>
                
                	<div id="contact_form">
                
                        <h4>Quick Contact</h4>
                        
                        <form method="post" name="ContactForm" id="contact" action="email.php" onsubmit="return ValidateContactForm();">
                            
                            <div class="col_w340 float_l">
                            
                                <label for="author">Name (* Required):</label> <input name="author" type="text" class="input_field" id="author" maxlength="40" />
                              	<div class="cleaner_h10"></div>
    
     <label for="subject">Subject:</label> <input name="subject" type="text" class="input_field" id="subject" maxlength="40" />
                              	<div class="cleaner_h10"></div>
    
                                
                                <label for="email">Email (* Required):</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" />
                              	<div class="cleaner_h10"></div>
                                
                                
    Type verification image:<br />
    <input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid #CCCCCC; width:180px; height:14px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"/>
    <img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" /><br />
    <br />                        
    
    </div>
                            
    
    
                            <div class="col_w340 float_r">
                            
                                <label for="text">Message (*Required):</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
                                <div class="cleaner_h10"></div>
                                
                                <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" />
                                <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" />
                                
                            </div>
                            
                       </form>
    
                </div> 
    
                <div class="cleaner"></div>
                
            </div>
            <div id="templatemo_content_bottom"></div>
    	</div>
        
        <div id="templatemo_sp_box">
        
        	<div class="col_w340 float_l">
             
    			</div>
            </div>
            
            <div class="col_w340 float_r">
            
    			</div>
            </div>
        
        </div>
        
        <div id="templatemo_footer">
    
          
            Copyright © 2011 <a href="www.twitter.com/">Starr</a><br/> 
            <a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a> 
            by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a>
        
        </div> <!-- end of templatemo_footer -->
        
    </div> <!-- end of templatemo_wrapper -->    
    
    </body>
    </html>
    [PHP]

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>


    <?php


    $first_name=$_POST['name'];
    $email_address=$_POST['email'];
    $subject=$_POST['subject'];
    $message=$_POST['text'];

    mail("starr05@gmail.com","Subject: $subject",
    $message, "From: $first_name <$email_address>");

    echo "Thank you for using our mail form.<br/>";
    echo "Your email has been sent.";
    ?>




    </body>
    </html>

    [PHP]

  • #11
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Code:
    I went back and changed things in my script, but still getting errors (Expected ')' Line:13 Char:125)
    
    } else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a- - This is line 13.
    It means the parentheses are unbalanced. Just balance them.

  • #12
    New Coder
    Join Date
    Feb 2009
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Logic Ali View Post
    Code:
    I went back and changed things in my script, but still getting errors (Expected ')' Line:13 Char:125)
    
    } else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a- - This is line 13.
    It means the parentheses are unbalanced. Just balance them.
    I just added a parentheses and still picks up the same error.

  • #13
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by saxchick1 View Post
    I just added a parentheses and still picks up the same error.
    This line has balanced parentheses, although it still has more than it needs.
    The regex is still wrong but you can work on that.

    if( !(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(document.ContactForm.email.value ) ) )

  • #14
    New Coder
    Join Date
    Feb 2009
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What is regex? This is my first time having to validate an email address, so I am not too sure of things.

  • #15
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,338
    Thanks
    29
    Thanked 282 Times in 276 Posts
    Quote Originally Posted by saxchick1 View Post
    I went back and changed things in my script, but still getting errors (Expected ')' Line:13 Char:125)

    } else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a- - This is line 13.
    Quote Originally Posted by saxchick1 View Post
    Code:
    function ValidateContactForm() {
      if (document.getElementById("author").value === "") {
        window.alert("Please provide a detailed description or comment.");
        document.getElementById("author").focus();
      } else if ((!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(document.ContactForm.email.value)) { 
        alert ("Invalid email address!  Please retry.");
        document.ContactForm.email.value == "";  // clear the field
        document.ContactForm.email.focus();  // and refocus on it
      } else if (document.getElementById("text").value === "") {
        window.alert("Please provide a detailed description or comment.");
        document.getElementById("text").focus();
      } else {    
        return true; // successful
      }
      return false; // failed validation
    }
    A review of this code indicates that you're missing two RIGHT PARENTHESIS characters immediately before the RIGHT CURLY BRACKET character at the end of the line containing the regular expression.

    Another way of looking at it is that you have two too many LEFT PARENTHESES characters at the start of your if statement's condition (on the line containing the regular expression). One of these is immediately before the EXCLAMATION MARK character and the other is immediately after it.

    Additionally, you have this problematic code: document.ContactForm.email.value == ""; // clear the field. Because you used the equality operator (i.e., ==) instead of the assignment operator (i.e., =), this line will simply return true or false and otherwise have no effect.

    (And, as I've already mentioned, you should be using IDs to reference your elements, so document.ContactForm.email.value should be document.getElementById("email").value.

    Quote Originally Posted by saxchick1 View Post
    Also, I think I may have two different ways of calling the 'name' textbox, in my php I have it as name, and in my form I have it as 'author'
    This is not a PHP problem. Next time, please submit processed HTML or XHTML code that does not include any PHP code that can be copied and pasted into a text editor so that people can test your code without jumping through hoops.

    Currently, to test your code, one has to (A) render it as HTML with errors due to PHP code; (B) render it as XHTML/XML with fatal errors due to PHP code (that will prevent the entire document from displaying assuming that it displays at all); (C) look through your code and fix all of the errors that have nothing to do with your primary problem before testing for your problem; or (D) pick out parts of your document and transplant them to a new, properly written document to test them. (I ended up going with D.)
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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