PHP + Javascript form validation

I'm creating a contact form for a company and i'm hitting a wall!

The form is working and all, but i can't seem to get the validation working properly.

I'd like to be able to require that the name is given and also EITHER a phone number OR email address.

My knowledge of javascript (and php for that matter) is pretty weak, but i've been able to get the form to erquire phone or email be entered... the problem is you can submit this form without entering a name as long as you enter an email or phone number...

What am i missing?

<?php
if (!isset($_POST['sendMeNow'])) {
?>

<html>
<head>
<script type="text/javascript">

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}

function checkPhoneEmail() {
if((document.getElementById('email').value=='' || document.getElementById('email').value==null) && (document.getElementById('phone').value=='' || document.getElementById('phone')==null)) {
alert("You must fill in a contact mehod: Phone or Email");
return false;
}
else { return true; }
}
</script>
</head>
<body>
<form name="contact" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<table width="550" cellpadding="2" cellspacing="2">
<tr>
<td><select name="serviceCenter" onchange="document.contact.submit();">
<option>Select Location</option>
<option value="Location 1" <?php if ($_REQUEST['serviceCenter'] == 'Location 1') {echo 'selected="selected"';}?>>Location 1</option>
<option value="Location 2" <?php if ($_REQUEST['serviceCenter'] == 'Location 2') {echo 'selected="selected"';}?>>Location 2</option>
<option value="Location 3" <?php if ($_REQUEST['serviceCenter'] == 'Location 3') {echo 'selected="selected"';}?>>Location 3</option>
</select></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>
<?php
switch ($_REQUEST['serviceCenter']) { //check serviceCenter value
case 'Location 1':
?>
<div id="google-map">
<!-- insert map code here -->
</div>
<div id="location-info">
<!-- location information here -->
</div>
<br />
<?php break;
case 'Location 2': //if the value is Warren, MI then display the map
?>
<div id="google-map">
<!-- insert map code here -->
</div>
<div id="location-info">
<!-- location information here -->
</div>
<br />
<?php break;
case 'Location 3':
?>
<div id="google-map">
<!-- insert map code here -->
</div>
<div id="location-info">
<!-- location information here -->
</div>
<br />
<?php break;
default:
?>
<br />
<?php
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" onsubmit="return checkPhoneEmail()">
<table width="550" cellpadding="2" cellspacing="2">
<tr>
<td>Name:</td>
<td><input type="text" name="name" /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" id="email" /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone" id="phone" maxlength="10" /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name="message" cols="40" rows="7"></textarea></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="sendMeNow" value="Submit" onClick="MM_validateForm('name','','R','email','','NisEmail','phone','','NisNum');return document.MM_returnValue" />&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="Reset" /></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

</form>

</body>
</html>

<?php

} else {

$name=$_REQUEST['name'];
$phone = stripslashes($_REQUEST['phone']);
$email = $_REQUEST['email'];
$location = $_REQUEST['serviceCenter'];
$serviceCheck = '';
foreach ($_REQUEST['serviceType'] as $value) {
$serviceCheck .= "\n $value";
}
$message = $_REQUEST['message'];

switch ($_REQUEST['serviceCenter']) {
case 'Location 1':
$to = "location1@store.net";
break;
case 'Location 2':
$to = "location2@store.net";
break;
case 'Location 3':
$to = "location3@store.net";
break;
default:
$to = "location1@store.net";
break;
}

$msg = "You have received a message from your website's 'Contact Page'. The information the visitor submitted can be seen below:\n\n\n\nContact Information\n\nName: $name\nPhone: $phone\nEmail: $email\n\nService Requested: $serviceCheck\n\nMessage:\n$message";

mail("$to", "Contact from the website", "$msg", "From: $email");

?>
<html>
<head></head>
<body>
Thank you...
</body>
</html>
<?php
}
?>

Javascript form validation

I have problem with my javascript form validation... Validation works only on last question and I can't understand why it doesn't work on other questions..Html code :<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional. ...

Client side JavaScript form validation (uses ajax) - Form won't submit, HELP!

I've literally tried everything. Read 26 tutorials, interchanged code, etc.My validation functions all work. My AJAX functions work (tested manually using servlet URL's).The second servlet validates the reCaptcha form that's generated on my webpage. After the form is validated, even if everything's ...

javascript form validation subscribe to multiple mailing lists

<script type="text/javascript">function changeinput(){if(document.getElementById(“MERGE2”).value=checked){document.getElementById("newsletteru").value = "sadfjflaskfj";document.getElementById("newsletterid").value = "345345";}else{document.ge ...

Javascript form validation error

Am new to this forum, as you can see this is my first post.Am having problem in validating my form, so i like you guys to help me out.<html><head><title>Javascript form Validation</title><script language="javascript"><!--function formValid(){var user = ducu ...

Simple Javascript Form Validation

I'm trying to do a simple validation to see if the field is blank, if it is, I want to write a message to a div. I've added the function call to an onclick. It seems to be set off no matter if there is a value or not, and what's more, the fields are clearing out when the link is clicked. My brain is ...

JavaScript Form Validation Doesn't Recognize a Value when using IE

Anybody would help me on this one , It's driving me crazy, I am making this drop down menu with several options depending on your choice. It works fine in FF but when I tried in IE simply won't recognize a Value.The window keep popping out even though you choose an option, this way won't let me go t ...

Best Javascript Form Validation Display Technique

I'm looking for different JS form validation techniques. I've seen quite a few but nothing that really stands out. I'm particularly interested in finding design techniques...ie: how and where are the errors displayed inside a form?I realize that I can't count on JS for validation, but I'm trying to ...

Help needed! Javascript Form Validation

Below is some code I wrote for my assignment that is due tonight; however, I can't seem to get any of the validation features to work. Can someone help me? I'm really new to javascript and struggling through it, but really want to figure this out.Here are the things I'm trying to do:-Validate each t ...

Javascript Form Validation

Basically I need the form to say "You have missed fields x, y, z" and to deny submitting the form until those fields are filled.Right now what happens is, it tells the user that "You are missing fields x, y, z" but then once the user clicks ok to the pop up it still asks for the ...

JavaScript Form Validation Needed

Im looking for a form which has java script applied to it and that checks to see if required fields are entered into the imput boxes..The form is fairly simple and just has these fields, name, surname, email, phone number and your number...Can anybody point me in the right direction? ...

JavaScript Form Validation

As I explained in the previous post, am performing some valdiations on the fields like usernmae, password etc of a registration page. But, the thing is I'm unable to perform any validations when am cliking the register button(the valdiate function is not getting invoked at all) . It is directly navi ...

JavaScript Form Validation

I am using the validations provided in a tutorial to validate a registration page. But when I open the form in IE, it's not performing any of the validations after clicking register button and submitting the form. It does not navigate to the page specified in action tag and not even giving the alert ...

Javascript form validation when submit button is pressed?

I created a form which has a lot of textboxes, checkboxes and select-lists which are getting filled up by the records from a database table. I am basically creating an edit screen for a record.No I want to check all these input elements using javascript validation. I want this to performed when a bu ...

Javascript Form Validation

everyone, first I would like to say that I'm clueless when it comes to Javascript. I have no idea what to do about it.here's the thing, on my website [link (http://www.icarwakim.com)] I have a small search engine to allow the users to search for properties.The first field in the search block is ...

Javascript Form Validation help

Hi, I'm using radio buttons that when someone checks one of the radio buttons, it does the calculation (like if you check the add radio button, it'll do the adding operation) and has it displayed on the result text box. This is what I have:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict/ ...

JavaScript form validation

I have a nice working script which I've used on a page out on the web, it validates name and organisation fields for a certain length, makes sure the input isnt numeric and isnt empty.I also have an email address checking function, using a regular expression.the final validation function makes sure ...

javascript form validation in Netscape 6 failing

I would aprreciate some suggetsions on this one. Thie javascript should check to see that either the payment1 or payment2 radio button is checked and if not alert the user to check one of them. Works fine in IE 6Here is the javascript: <script language="javascript" type="text/javas ...

php and javascript form validation

In the past I have always validated the data once it was passed to the next part of the script. I have always thought this was inconveinent because you have to wait for a page load to fidn out you left a field blank or your email is incorrect etc.What I am looking to do.. Is to make the form validat ...

Javascript Form Validation

have created a form that sends the contents to a mysql database.i want the form to be validated using javascript b4 hand, it works without the php to get it to send to the database but when i press submit, it won't validate here is my code...<html xmlns="http://www.w3.org/1999/xhtml" ...

JavaScript Form Validation

I am trying to create a form validation script which must be written in JavaScript (no jQuery allowed). I think that I have the idea right but something is going wrong with the script. Each of the 4 validation rules have certain criteria that needs to be checked which I have included as comments. I ...

Multi-line Alert w/ Javascript Form Validation

I should probably preface this post with the fact that I'm a total Javascript noob so if you could keep answers as easy to understand as possible I would greatly appreciate it.I created a contact form in HTML that uses Javascript to validate that all of the fields have been entered. I know this is f ...

Javascript Form Validation Issue

I'm using a Javascript form validation script and I can't get the checkbox area of it to work correctly. Could someone help me out with it please?function validateForm(oForm){//oForm refers to the form which you want to validateoForm.onsubmit = function() // attach the function to onsubmit event{var ...

javascript form validation

I want to make this script run the validate function again as if it was originally returned as false. Right now, this script runs, but isn't returning false. And if I can get it to return false, I want to because to to give the user a chance to fill in the 'error' inputs and resubmit the form. Right ...

Javascript form validation stopped working

I have multipage form that requires validation of specific fields before it will move the user to the next page. It was working, but I made some styling changes, and now no error message come up, nor will it advance to the next page when all fields are populated correctly. In IE 7, I get a popup mes ...

unobtrusive javascript form validation

All... sorry if this post is a duplicate. I am building an oop version of the ever so popular form validation script. Everything worked when I had separate functions for everything... but now I'm having a problem with attaching the function to the submit event of the form. Right now I have it in an ...

JavaScript Form Validation Script

Need help...this script just simply isn't working for me.function validateForm() {with(document.form) {var reason = "";reason += validatePartName(partname);reason += validatePartSurname(partsurname);reason += validatePartEmail(partemail);reason += validateParentName(parentname);reason += v ...

javascript form validation not working

I had somebody design this website and I have basic html skills and I've tried so many methods and several hours trying to get form validation and I can't get it to work. I have 1 form on this site where people have to enter a 3 digit number and even if you don't enter any number at all and click ...

Javascript form validation for an incrementing text field name

I have a form that lists a text field based on the number of returns from a query. Do while not rs.eof i=i+1 <input name="Reading<%=i%>"> Loop I need to create a validation for this entry so that it does not excede 10 characters. On a different form I used this in the heading, ...

Javascript form validation

I neeed help with a script validation:All the form requires is;full name and;full address or email address;the option is that not the address & email address are both required, only one of them, can someone help me?Ken ...

JavaScript form validation - please help

Hello. I am new to JavaScript and need to make sure that all of the fields in this form are populated before the submission will go through, otherwise a message needs to popup saying which fields are missing information. Can someone please help. My code so far is:<html><head><title ...