Jump to content

PHP + Javascript form validation


MainStWebGuy

Recommended Posts

Hello all,

 

I have what i'm thinking may be an elementary question, but it's throwing me for a loop!

 

I have a very simple contact form on a website that looks something like this:

 

....
<form action="<?php $_SERVER['PHP_SELF'];?>" method="POST" >
    <table>
        <tr>
            <td>Name:</td>
            <td><input type="text" name="name" /></td>
        </tr>
        <tr>
            <td>Phone:</td>
            <td><input type="text" name="phone" /></td>
       </tr>
       <tr>
            <td>Email:</td>
            <td><input type="text" name="email" /></td>
       </tr>
       <tr>
            <td> </td>
            <td><input type="submit" name="sendMe" value="Send" onClick="MM_validateForm('name','','R','phone','','RisNum','email','','RisEmail'); return document.MM_returnValue" /></td>
       </tr>
    </table>

 

Rather than requiring both the email and the phone be given, i thought i would try to make an if...else stastement to check to see if email AND phone were blank, throw an alert.

 

I'm still pretty new to php and very new to javascript so i'm not sure how exactly to code this. Where would be the best place for this if...else statement to go?

 

how can i alert the user of a problem without submitting the data and without requiring them to hit their "Back" button?

 

Thanks guRus!

    -a dedicated newb

Link to comment
Share on other sites

its easier if you give each form element an ID as well as a name attribute.

 

I think this would work

<script type="text/javascript">
function validateForm() {
  if((getElementById('email').value=='' || getElementById('email').value==null) && (getElementById('phone').value=='' || getElementById('phone')==null)) {
     alert("Email and Phone cannot be blank");
     return false;
  }
  else { return true; }
}
</script>   

 

and the new form

....
<form action="<?php $_SERVER['PHP_SELF'];?>" method="POST" onsubmit="return validateForm()">
    <table>
        <tr>
            <td>Name:</td>
            <td><input type="text" name="name" id="name"/></td>
        </tr>
        <tr>
            <td>Phone:</td>
            <td><input type="text" name="phone" id="phone"/></td>
       </tr>
       <tr>
            <td>Email:</td>
            <td><input type="text" name="email" id="email"/></td>
       </tr>
       <tr>
            <td> </td>
            <td><input type="submit" name="sendMe" value="Send"/></td>
       </tr>
    </table>

Link to comment
Share on other sites

Sorry to bother you again hehe but i tried to re-create a "dubmed down version" and im having problems:

 

<?php

if (!isset($_POST['sendMe'])) {
?>
<html>
<head></head>

<script type="text/javascript">
function checkPhoneEmail() {
  if((getElementById('email').value=='' || getElementById('email').value==null) && (getElementById('phone').value=='' || getElementById('phone')==null)) {
     alert("Email and Phone cannot be blank");
     return false;
  }
  else { return true; }
}
</script>
<body>

<form action="<?php $_SERVER['PHP_SELF'];?>" method="POST" onSubmit="return checkPhoneEmail()">
<label>Name: <input type="text" name="name" id="name"  /></label><br />
<label>Phone: <input type="text" name="phone" id="phone"  /></label><br />
<label>Email: <input type="text" name="email" id="email"  /></label><br />
<label><input type="submit" name="submit"  on/></label>
</form>


</body>
</html>
<?php
} else {

$name=$_POST['name'];
?>

<html>
<head>
<script type="text/javascript">
function checkPhoneEmail() {
  if((getElementById('email').value=='' || getElementById('email').value==null) && (getElementById('phone').value=='' || getElementById('phone')==null)) {
     alert("Email and Phone cannot be blank");
     return false;
  }
  else { return true; }
}
</script>
</head>
<body>

<p>Thank you, <?php echo $name;?>! You are awesome!!!!</p>

</body>
</html>
<?php
}
?>

 

It looks like it isn't requiring either of the fields... it could totally be a typo, but i can't seem to find it!

Link to comment
Share on other sites

one mistake on my part.  i forgot the "document." before getElementById

and i dont know what you were trying to do, but a lot of things were screwed up with your organization

 

<?php
  if(isset($_POST) && isset($_POST['submit'])) {
  	echo "Thanks for your submission " . $_POST['name'];
  	exit();
  }
  
?>

<html>
<head>

<script type="text/javascript">
function checkPhoneEmail() {
  if((document.getElementById('email').value=='' || document.getElementById('email').value==null) && (document.getElementById('phone').value=='' || document.getElementById('phone')==null)) {
     alert("Email and Phone cannot be blank");
     return false;
  }
  else { return true; }
}
</script>
</head>
<body>

<form action="<?php $_SERVER['PHP_SELF'];?>" method="POST" onSubmit="return checkPhoneEmail()">
<label for="name">Name:</label><input type="text" name="name" id="name"  /><br />
<label for="phone">Phone:</label><input type="text" name="phone" id="phone"  /><br />
<label for="email">Email:</label><input type="text" name="email" id="email"  /><br />
<label><input type="submit" name="submit"  on/></label>
</form>


</body>
</html>

Link to comment
Share on other sites

Haha yeah i'm slowly grasping concepts... it's sorta like listening to a little kid start to talk and no one can understand them except their parents hehe.

 

Just out of couriosity, why do you do the isset check for $_POST in addition to the $_POST['submit'] ?

 

Thanks again Lonewolf that totally did the trick!!

 

Link to comment
Share on other sites

Ok, I've been at it for a few hours now and just can't get the concepts you've showed me to work with my form.  >:(

 

If i could borrow your eyes and brain for one more time today i would really appreciate it!!!

 

What i'm trying to do is have one page that will first ask the user to select a location. Once that selected, my switch statement will display that location's physical address, phone number and a iframe to google maps. From there, a new form will gather some simple contact information that will be sent to the appropriate store.

 

i've dumbed down the form i'm using a lot and tried to include only the necessary code:

 

Sorry it's so messy!!! i suck at organizing code :-(

<?php
if (!isset($_POST['sendMeNow'])) {
?>
<!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" />
<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 $_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="Auburn Hills, MI" <?php if ($_REQUEST['serviceCenter'] == 'Auburn Hills, MI') {echo 'selected="selected"';}?>>Auburn Hills, Michigan</option>
							<option value="Warren, MI" <?php if ($_REQUEST['serviceCenter'] == 'Warren, MI') {echo 'selected="selected"';}?>>Warren, Michigan</option>
							<option value="Newark, DE" <?php if ($_REQUEST['serviceCenter'] == 'Newark, DE') {echo 'selected="selected"';}?>>Newark, Delaware</option>
						</select></td>
					<td> </td>
					<td> </td>
					<td> </td>
				</tr>
			</table>
		</form>	
<?php
switch ($_REQUEST['serviceCenter']) { //check serviceCenter value
	case 'Auburn Hills, MI': //if the value is Auburn Hills, MI then display the map
?>		
<div id="fenkell-auto-repair">
<!--insert map code here -->
</div>
		<form action="<?php $_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> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Email:</td>
					<td><input type="text" name="email" id="email" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Phone: (10 digit total)</td>
					<td><input type="text" name="phone" id="phone" maxlength="10" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Service(s) Requested: </td>
					<td><input type="checkbox" name="serviceType[]" value="Auto Repair" /> Auto Repair   <input type="checkbox" name="serviceType[]" value="Auto Glass" /> Auto Glass    <input type="checkbox" name="serviceType[]" value="Tires/Wheels" /> Tires/Wheels   <br /><input type="checkbox" name="serviceType[]" value="Oil Change" /> Oil Change   <input type="checkbox" name="serviceType[]" value="Fleet Services" /> Fleet Services   <input type="checkbox" name="serviceType[]" value="Other" /> Other</td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Message:</td>
					<td><textarea name="message" cols="40" rows="7"></textarea></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td> </td>
					<td><input type="submit" name="sendMeNow" value="Submit" onSubmit="MM_validateForm('name','','R','email','',RisEmail','','phone','','RisNum'); return document.MM_returnValue" />   <input type="reset" name="reset" value="Reset" /></td>
					<td> </td>
					<td> </td>
				</tr>																																																		
			</table>
		</form>				
</body>
</html>
<?php break;
	case 'Warren, MI': //if the value is Warren, MI then display the map
?>
<div id="fenkell-auto-repair">
<!--insert map code here -->
</div>
		<div id="contact-fenkell-automotive">
		<form action="<?php $_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> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Email:</td>
					<td><input type="text" name="email" id="email" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Phone:</td>
					<td><input type="text" name="phone" id="phone" maxlength="10" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Service(s) Requested: </td>
					<td><input type="checkbox" name="serviceType[]" value="Auto Repair" /> Auto Repair   <input type="checkbox" name="serviceType[]" value="Auto Glass" /> Auto Glass    <input type="checkbox" name="serviceType[]" value="Tires/Wheels" /> Tires/Wheels   <br /><input type="checkbox" name="serviceType[]" value="Oil Change" /> Oil Change   <input type="checkbox" name="serviceType[]" value="Fleet Services" /> Fleet Services   <input type="checkbox" name="serviceType[]" value="Other" /> Other</td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Message:</td>
					<td><textarea name="message" cols="40" rows="7"></textarea></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td> </td>
					<td><input type="submit" name="sendMeNow" value="Submit" onSubmit="MM_validateForm('name','','R','email','',RisEmail','','phone','','RisNum'); return document.MM_returnValue" />   <input type="reset" name="reset" value="Reset" /></td>
					<td> </td>
					<td> </td>
				</tr>																																																		
			</table>		
	</form>				
</body>
</html>
<?php break;

	case 'Newark, DE': //if the value is Newark, DE then display the map
?>
<div id="fenkell-auto-repair">
<!--insert map code here -->
</div>

	<form action="<?php $_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> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Email:</td>
					<td><input type="text" name="email" id="email" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Phone:</td>
					<td><input type="text" name="phone" id="phone" maxlength="10" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Service(s) Requested: </td>
					<td><input type="checkbox" name="serviceType[]" value="Auto Repair" /> Auto Repair   <input type="checkbox" name="serviceType[]" value="Auto Glass" /> Auto Glass    <input type="checkbox" name="serviceType[]" value="Tires/Wheels" /> Tires/Wheels   <br /><input type="checkbox" name="serviceType[]" value="Oil Change" /> Oil Change   <input type="checkbox" name="serviceType[]" value="Fleet Services" /> Fleet Services   <input type="checkbox" name="serviceType[]" value="Other" /> Other</td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Message:</td>
					<td><textarea name="message" cols="40" rows="7"></textarea></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td> </td>
					<td><input type="submit" name="sendMeNow" value="Submit" onSubmit="MM_validateForm('name','','R','email','',RisEmail','','phone','','RisNum'); return document.MM_returnValue" />   <input type="reset" name="reset" value="Reset" /></td>
					<td> </td>
					<td> </td>
				</tr>																																																		
			</table>															
		</form>
</body>
</html>
<?php break;
	default:?>

		<h2>Complete the Form to Contact Us Now!</h2>	
		<form action="<?php $_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> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Email:</td>
					<td><input type="text" name="email" id="email" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Phone:</td>
					<td><input type="text" name="phone" id="phone" maxlength="10" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Service(s) Requested: </td>
					<td><input type="checkbox" name="serviceType[]" value="Auto Repair" /> Auto Repair   <input type="checkbox" name="serviceType[]" value="Auto Glass" /> Auto Glass    <input type="checkbox" name="serviceType[]" value="Tires/Wheels" /> Tires/Wheels   <br /><input type="checkbox" name="serviceType[]" value="Oil Change" /> Oil Change   <input type="checkbox" name="serviceType[]" value="Fleet Services" /> Fleet Services   <input type="checkbox" name="serviceType[]" value="Other" /> Other</td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Message:</td>
					<td><textarea name="message" cols="40" rows="7"></textarea></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td> </td>
					<td><input type="submit" name="sendMeNow" value="Submit" onSubmit="MM_validateForm('name','','R','email','',RisEmail','','phone','','RisNum'); return document.MM_returnValue" />   <input type="reset" name="reset" value="Reset" /></td>
					<td> </td>
					<td> </td>
				</tr>																																																		
			</table>															

		</form>
</body>
</html>
<?php
}
}	else {

//set variables

//set message to be sent


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

?>
<html>
<head></head>

Thank you!

</body>
</html>
<?php
}
?>

 

Now i know a lot of people come on here simply wanting their problem to go away, but i'd really like to learn all i can so any tips, advice etc will be taken to heart and greatly appriciated!

 

thanks again,

J

Link to comment
Share on other sites

What's wrong with that?

 

Here's what I see you should do since you didn't tell me what's wrong with it.

 

1. Don't use Dreamweaver functions.

2. Add the onsubmit attribute to the first form.

3.

<form name="contact" action="<?php $_SERVER['PHP_SELF'];?>" method="POST">

For all lines of that, either take out action attribute or change add echo - <?php echo $_SERVER['PHP_SELF']; ?>

Link to comment
Share on other sites

Aye Ken, and thanks for the reply.

 

The more i learn about coding the less i like dreamweaver in general!!

 

Sorry i didn't explain what's wrong with the code haha (oops).

 

With the code i've provided last, i can submit the form without filling in ANY fields.

 

I would like the name to be required, the email (if entered) in the correct format and the phone (if entered) to be a number. Per the earlier post, it doesn't matter to me if the visitor enters in the email or the phone, but we need them to enter one of them.

 

Again, sorry for leaving all that out!

Link to comment
Share on other sites

2. Add the onsubmit attribute to the first form.

3.

<form name="contact" action="<?php $_SERVER['PHP_SELF'];?>" method="POST">

For all lines of that, either take out action attribute or change add echo - <?php echo $_SERVER['PHP_SELF']; ?>

 

just a question from a newb... for the number 2. answer you gave, why does the first form need that attribute? the first form should only be asking them to select from a drop down menu and the second form will have the input fields. (not trying to argue, just trying to understand  :) )

Link to comment
Share on other sites

any time you are trying to use a php variable to define the action of the form, you need to echo it, otherwise it will not be displayed and the form wont be submittable.

 

Simplest way to see what it does is to have two simple forms.

<form name="test1" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
</form>

<form name="test2" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
</form>

 

load up this page and right click and view source.  see what the difference is between the two action fields

Link to comment
Share on other sites

Finally got it just about finished... thanks so much LoneWolf and Ken for you insight and help!

 

Everything is working great now with the required fields accept for one little thing... I can submit this form without having anything in the name field as long as i have an email address or phone number... what am i leaving out?

 

revised code (thanks again guys!):

<?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> </td>
					<td> </td>
					<td> </td>
				</tr>
			</table>
		</form>	
<?php
switch ($_REQUEST['serviceCenter']) { //check serviceCenter value
	case 'Location 1': //if the value is Auburn Hills, 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 'Warren, MI': //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 'Newark, DE': //if the value is Newark, DE then display the map
?>
<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> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Email:</td>
					<td><input type="text" name="email" id="email" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Phone:</td>
					<td><input type="text" name="phone" id="phone" maxlength="10" /></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td>Message:</td>
					<td><textarea name="message" cols="40" rows="7"></textarea></td>
					<td> </td>
					<td> </td>
				</tr>
				<tr>
					<td> </td>
					<td><input type="submit" name="sendMeNow" value="Submit" onClick="MM_validateForm('name','','R','email','','NisEmail','phone','','NisNum');return document.MM_returnValue" />   <input type="reset" name="reset" value="Reset" /></td>
					<td> </td>
					<td> </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
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.