weird validation problem

Associate
Joined
19 Jul 2006
Posts
1,847
can someone please have a look at this i dont really understand what it going on with the validation of this form
http://www.hargitech.co.uk/test/backup/contact_us.php

Now in safari it works to the best of my knowledge.
Its the phone number field that is causing the problems

it should only let the user send the form if the field contains 9 or more numbers and give a warning. In firefox it seams to let anything go for the phone number field.

The validation is in http://www.hargitech.co.uk/test/backup/contact_form.php

or code is here
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>
<title>Test</title>

<link rel="stylesheet" type="text/css" href="css/reset.css" />  
<link rel="stylesheet" type="text/css" href="css/style.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" type="text/css" href="css/ie-borders.css" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="css/style_cf.css" />
<link rel="stylesheet" type="text/css" href="css/prettyPhoto.css" media="screen" />

<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/jquery.cycle.all.min.js"></script>
<script type="text/javascript" src="js/jquery.tools.min.js"></script>
<script type="text/javascript" src="js/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>   
<script type="text/javascript" src="js/Aller_Light_400.font.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script> 
<script type='text/javascript' src='js/jquery.imgr.min.js'></script>
<script type='text/javascript' src='js/jquery.jscrollpane.min.js'></script>
<script type='text/javascript' src='js/jquery.mousewheel.js'></script>
<script type="text/javascript" src="js/jquery.tweet.js"></script>
<script type='text/javascript' src='js/script.js'></script>
<!--[if lte IE 8]>
<script type='text/javascript' src='js/curvycorners.js'></script> 
<![endif]-->
	
<!--[if gte IE 9]>
<script type="text/javascript">
Cufon.set('engine', 'canvas');
</script>
<![endif]-->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-23724318-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body>

<!-- wrapper -->
<div id="container">
    
	<!-- header -->
	
 
	<!-- contents -->
	<div class="border">
	
		<!-- page title --> 
		<div class="head_text"><h2>Contact Us</h2></div>
		<!-- / page title --> 
	    
		
	 
		<div class="content_background sub">
		<div class="content sub">
		
			<!-- left content -->
			<div class="left">
			    
					<!-- contact form -->
					<h5>Contact Form</h5>

					<p><i>(*) denotes required information.</i></p>					
					<div id="result"></div>
					<div id="contact_form">
						<form action="contact_form.php" id="validate_form" method="post" class="showtextback">
							<ul>
								<li><label for="name">Your Name: (*)</label><input id="name" type="text" name="name" value="" class="required" /> </li>
								<li><label for="phone">Your Phone number: (*)</label><input id="phone" type="text" name="phone" value="" class="required"	 /> </li> 
								<li><label for="email">Your Email: (*)</label><input id="email" type="text" name="email" value="" class="required"	 /> </li> 
								<li><label for="message">Your message: (*)</label><textarea  id="message" name="message" rows="8" cols="40"	class="required"></textarea></li>
								<li><input type="submit" value="Send"  /><span class="loading"></span></li>
							</ul>
						</form>
					</div>
					<!-- /contact form -->
		   
			</div>
			<!-- / left content -->
		    
			<!-- sidebar -->
			<div class="sidebar"><div class="sidebar_back"><div class="sidebar_back2">
				

				
				
			
				
	   
			<div class="clear"></div>
			</div></div></div>
			<!-- / sidebar -->
		
		<div class="clear"></div>
		</div>
		</div>
	</div>
	<!-- / contents  -->


</div>
<!-- / wrapper -->

<!-- footer wrapper -->
<div class="footer_background"> 
	<div class="border">
		
	</div>
</div>
<!-- /footer wrapper -->

</body>
</html>

and here
PHP:
<?php
// edit these lines
$your_name="testing";
$your_email="[email protected]";
$your_web_site_name="";
?>

<?php 
//If the form is submitted
if(isset($_POST['name'])) {

		//Check to make sure that the name field is not empty
		if(trim($_POST['name']) === '') {
			$hasError = true;
		} else {
			$name = trim($_POST['name']);
		}
		
		//Check to make sure sure that a valid email address is submitted
		if(trim($_POST['email']) === '')  {
			$hasError = true;
		} else if (!preg_match('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$^', trim($_POST['email']))) {
			$hasError = true;
			$errorMessage = "Please enter a valid email address!";
		} else {
			$email = trim($_POST['email']);
		}

		 if (trim($_POST['phone'] === '')) 
    { 
        $hasError = true; 
    } 
    else if (!preg_match('(\d{9})', trim($_POST['phone']))) 
            { 
                $haserror = true; 
                $errorMessage = "Your phone number must have 9 digits"; 
            } 
            else 
            { 
                $phone = trim($_POST['phone']); 
            } 

		
		//company name
		if(isset($_POST['company_name'])) $company_name = trim($_POST['company_name']);

		//company url
		if(isset($_POST['company_url'])) $company_url = trim($_POST['company_url']);

			
		//Check to make sure comments were entered	
		if(trim($_POST['message']) === '') {
			$hasError = true;
		} else {
			if(function_exists('stripslashes')) {
				$comments = stripslashes(trim($_POST['message']));
			} else {
				$comments = trim($_POST['message']);
			}
		}



		//If there is no error, send the email
		if(!isset($hasError)) {

			$emailTo = $your_email;
			$subject = 'Contact Form Submission from '.$name;
			
			//message body 
			$body  ="Name: $name \n\n";
			$body .="Email: $email \n\n";
			$body .="Phone:$phone\n\n";
			if(isset($company_name)) $body .="Company Name:$company_name\n\n";
			if(isset($company_url)) $body .="Company Url:$company_url \n\n";
			$body .="Message: $comments";


			$headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
			
			mail($emailTo, $subject, $body, $headers);

			$emailSent = true;
	}
} 
?>

<?php if(isset($emailSent) == true) { ?>
	<div class="ok_box">
		<h3>Thanks, <?php echo $name;?></h3>
		<p>Your email was successfully sent. We will be in touch soon.</p>
	</div>
<?php } ?>

<?php if(isset($hasError) ) { ?>
	<div class="error_box">
		There was an error submitting the form.
		<br />
		<?php echo $errorMessage;?>
	</div>
<?php } ?>

TIA
 
Back
Top Bottom