Jump to content

form validation issues...


Codeman0013

Recommended Posts

Hey guys thanks in advance my problem is that i have a page that a user enters information and clicks submit and it goes to the next page and they can view their information on that page and then click mail or cancel to go back and fix their issue problem is it just skips all the verification on the first page and goes onto the next page. If its possible with javascript i would like to tell this page on the form instead of how i have it now have the form run just the javascript and have the javascript direct them to the next page if there are no errors on the page... please help me if you can i would be very thankful!

<!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=ISO-8859-1" /><title>Illinois Soybean Association Rust Watchers</title><meta name="description" content="" /><meta name="keywords" content="" /><link href="../../../../_lib/global.css" rel="stylesheet" type="text/css" media="screen" /><link href="../../../../_lib/selectors.css" rel="stylesheet" type="text/css" media="screen" /><script><!--		function contactCheck(){		var errors;		errors="";	if (SignUpForm.fieldname.value==""){			errors+="Your Name is required.";		}		if (SignUpForm.fieldaddress.value==""){			errors+="Your address is required.";		}		if (SignUpForm.fieldcity.value==""){			errors+="Your City is required.";		}		if (SignUpForm.fieldstate.value==""){			errors+="Your State is required.";		}		if (SignUpForm.fieldzip.value==""){			errors+="Your Zip Code is required.";		}		if (SignUpForm.fieldphone.value==""){			errors+="Your Phone Number is required.";		}		if (echeck(SignUpForm.fieldemail.value)!=true){			errors+="\nYou must enter a valid email address.";		}		if (errors==""){			SignUpForm.method="POST";			SignUpForm.submit();		} else {			alert(errors);		}	}	//Check E-mail quality	function echeck(str) {			var at="@"			var dot="."			var lat=str.indexOf(at)			var lstr=str.length			var ldot=str.indexOf(dot)			if (str.indexOf(at)==-1){			   return false			}			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){			   return false			}			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){				return false			}			 if (str.indexOf(at,(lat+1))!=-1){				return false			 }			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){				return false			 }			 if (str.indexOf(dot,(lat+2))==-1){				return false			 }			 if (str.indexOf(" ")!=-1){				return false			 }	 		 return true						}	//-->	</script></head><body><!-- HEADER --><?php require("../../../../_inc/header.php"); ?><!-- END OF HEADER --><div id="body">	<div id="left">		<div id="navContainer">			<ul id="nav">				<li class="select"><a href="/about/">ABOUT</a></li>				<li>					<ul>						<li><a href="/about/research/">Research</a></li>						<li><a href="/about/legislature/">Legislature</a></li>						<li><a href="/about/international-marketing/">International Marketing</a></li>						<li class="select"><a href="/about/programs/index.php">Programs</a></li>					</ul>				</li>				<li><a href="/membership/">MEMBERSHIP</a></li>				<li><a href="/soybean-uses/">SOYBEAN USES</a></li>				<li><a href="/education/">EDUCATION</a></li>				<li><a href="/soy-news/">SOY NEWS</a></li>				<li><a href="/resources/">RESOURCES</a></li>				<li><a href="/directors/">DIRECTORS</a></li>				<li><a href="/contact/">CONTACT</a></li>			</ul>		</div>		<div id="navBg"></div>	</div>	<div id="content">	   <div id="center">		  <p id="breadcrumbs"><a href="/">Home</a> » <a href="/about/">About</a> » <a href="/about/programs">Programs</a> » <a href="/about/programs/rust-watchers/">Rust Watchers</a> » <a href="index.php" class="select">Application</a></p>		  <h2>Soybean Rust Watcher Sign-Up</h2>	<img src="../../../../_img/defendYourYieldslogo.jpg" vspace="5" hspace="5" height="100" width="100" align="middle" /><FORM Method="Post" Action="verify.php" id=form2 name="SignUpForm" onsubmit="contactCheck()">			<table>				<tr>					<td>Name:</td>					<td><input type="text" name="fieldname"></td>					</tr>				<tr>										<td>Address:</td>					<td><input type="text" name="fieldaddress"></td>					</tr>				<tr>					<td>City:</td>					<td><input type="text" name="fieldcity"></td>					</tr>				<tr>					<td>State:</td>					<td><input type="text" name="fieldstate"></td>					</tr>				<tr>					<td>Zip Code:</td>					<td><input type="text" name="fieldzip"></td>					</tr>				<tr>					<td>Phone:</td>					<td><input type="text" name="fieldphone"></td>					</tr>				<tr>					<td>Fax:</td>					<td><input type="text" name="fieldfax"></td>					</tr>				<tr>					<td>E-Mail:</td>					<td><input type="text" name="fieldemail"></td>					</tr>				<tr>					<td></td>					<td><Input Type="Submit" Name="button" Value="Submit Application" onclick="contactCheck();">					</td>					</tr>  					</table>				 </form>	  </div>	   		<div id="right">				<div class="blue">					<h4>Program Sections</h4>						<ul>							<li><a href="/about/programs/soybean-quality/">The Soybean Quality Rewards Program</a></li>							<li><a href="/about/programs/rust-watchers/">Rust Watchers</a></li>							<li><a href="/about/programs/soyleaders/">SoyLeaders</a></li>							<li><a href="/about/programs/speakers-bureau/">Speakers Bureau</a></li>						</ul>							</div>										</div>	<br clear="both" /><!-- FOOTER -->	<?php require("../../../../_inc/footer.php"); ?> <!-- END OF FOOTER -->	</div></div></body></html>

Link to comment
Share on other sites

Hi,Couple of minor changes are required for the code you are using.First thing ins in the form tag.Return a boolean value whether the form is valid or not. This could be done by using return false in the else part of the errors = "" check of the contactCheck function.Also instead of using onsubmit = "contactCheck()" use onsubmit = "return contactCheck()" Finally in the contactCheck function if the error == "" then add the line below before the SignUpForm.submit() statement: SignUpForm.action= <Your Url>; This should solve your problem.Let me know for any further issues.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...