Hi,

I really could use some help. I realize there are probably lots of posts on validating forms with Javascript, but I have been at this all day and been pouring through Google and I havenít found what Iím looking for Ė I feel like my validation is close, but I just canít get it to work in two areas. They may be related; they may not, but Iím really stuck. I have a contact form (only three fields, name, email, and message). I want to make sure that there is something in each field and that the email is at least sort of legit before the message is sent through.

Iíve been trying to mesh tutorials and this is what Iíve come up with. However, my ďYour message has been sentĒ alert which I was trying to apply at the end (if everything was verified) never comes through and Iím absolutely stumped. Any pointers would be greatly appreciated.

Code:
<script type="text/javascript">
function checkform()
{
	if (document.contactAPC.name.value == '')
	{
		alert('Please enter a name.');
		return false;
	}
	else if(document.contactAPC.email.value == '')
	{
		alert('Please enter an email address.');
		return false;
	}
	else if(document.contactAPC.message.value == '')
	{
		alert('Please write a message.');
		return false;
	}
	else if(document.contactAPC.email.value != '')
	{	
	emailpattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
		if(!emailpattern.test(document.contactAPC.email.value)) 
			{
			 alert("Please enter a valid email address");
			 return false;
			}
	}
	else 
	{
		//Why can't I get this message to show?
				return true;
				alert("Your message has been sent.");
	}
}
</script>


</head>
<body>
<h2>Contact Us</h2>
	<form name="contactAPC" method="post" action="" onSubmit="return checkform()"> 
	Name <input type="text" size="26" id="name" name="name" class="txtfield_details"> 
	<br /> 
	<br />Email <input type="text" size="26" id="email" name="email" class="txtfield_details"> 
	<br /> 
	<br /> 
	Question/Comment
	<br /><textarea cols="24" rows="4" class="txtfield_details" name="message" id="message"></textarea> 
	<br /> 
	<br /><input type="submit" value="Submit" name="submit" class="btns" /> 
	<input type="reset" value="Clear" name="clear" class="btns" /> 
	</form>
Now my other issue is that when I attach the php file (below) to the form action (ie. action=Ēmyfile.phpĒ) Ė the form no longer even bothers to remotely try to validate. It just sends the contents straight through and I get my ďYour message has been sent messageĒ and this also confuses me. I thought checkform() needed to come back as true for the submit button to move the user forward.

Code:
<?php
$email = $_REQUEST['email'] ;

$message = 
$_POST["name"] ."\n". 
$_POST["email"] ."\n<>".
$_POST["message"] ."<>";

mail( "myemail@yahoo.com "From my Website",
$message, "From: $email" ); 
header("Location: http://www.mywebsite.org");
?>
If anyone could shed some light on this, it would make my day. Itís just been over a year since Iíve done Javascript and I never quite got the form validation to work right and it just a bit frustrating.

Thanks.