Solved

form submit not working

Posted on 2014-12-15
9
174 Views
Last Modified: 2014-12-16
I can't see what is wrong with the code below.  I am not getting the message that Dealer Code is required, nor is an email sent or the page redirecting if dealer code is not missing.

I am sure someone else will see my problem immediately :)

<?php 
		$errMessage='test';

        if ( !empty($_POST["sendMessage"])  )
        {
        		if ( empty($_POST["DealerCode"])) {  
    				$errMessage = 'You must enter a Dealer Code' ;
				} else {
					$errMessage='';
					$message = 'test';        		
					/*		
					$message = '';
					foreach($_POST as $key => $value)
					{
					    $message .= $key . ': ' . $value . "<br/>";
					} 
					*/       	
		            // To send HTML mail, the Content-type header must be set
		            $headers  = 'MIME-Version: 1.0' . "\r\n";
		            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		            $headers .= 'From: dealer submission <test@test.biz>' . "\r\n";
		            mail('test@yahoo.com','Message from Website',$message,$headers);

		        // MESSAGE SENT
		            header("Location: messageSent.php");
		            exit;                   
        		}
        }
?>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

	<style>
		body {
			padding-left: 30px;
		}
		th {
			background-color:#3399FF;
			text-align: center;
		}

		.column-one {
			width: 40px;
			text-align: center;
		}
		.column-two {
			width:450px;
		}
	</style>
	
</head>
<body>
	
	<br />
	<form method="post" action="priceEntry.php">
		<table width='85%'>
			<tr>
				<td>Dealer Code:<input type='text' name='DealerCode' /></td>
				<td><span class="error"><?php echo $errMessage;?></span></td>
				<td><button type="submit" class="btn btn-success" name="sendMessage">Submit</button></td>
			</tr>
		</table>
		<br/>
		<table border='1'>
	        <col class="column-one">
	        <col class="column-two">
	        <col class="column-three">
	        <col class="column-four">
	        <col class="column-five">
			<thead>
			<tr>
				<th></th>
				<th>Maintenance Services</th>
				<th>Price</th>
				<th>Shop Duration Time</th>
				<th>OP Code</th>
			</tr>
			</thead>
			<tr>
				<td>01</td>
				<td>Replace Engine Oil & Filter</td>
				<td><input type='text' name='MaintPrice01' /></td>
				<td><input type='text' name='MaintDuration01' /></td>
				<td><input type='text' name='MaintOPCode01' /></td>
			</tr>
			<tr>
				<td>02</td>
				<td>4 Wheel Alignment</td>
				<td><input type='text' name='MaintPrice02' /></td>
				<td><input type='text' name='MaintDuration02' /></td>
				<td><input type='text' name='MaintOPCode02' /></td>
			</tr>
			<tr>
				<td>03</td>
				<td>Wheel Balance (4 Wheel)</td>
				<td><input type='text' name='MaintPrice03' /></td>
				<td><input type='text' name='MaintDuration03' /></td>
				<td><input type='text' name='MaintOPCode03' /></td>
			</tr>
			<tr>
				<td>04</td>
				<td>Replace Air Cleaner Filter</td>
				<td><input type='text' name='MaintPrice04' /></td>
				<td><input type='text' name='MaintDuration04' /></td>
				<td><input type='text' name='MaintOPCode04' /></td>
			</tr>
			<tr>
				<td>05</td>
				<td>Replace Automatic Transaxle Fluid</td>
				<td><input type='text' name='MaintPrice05' /></td>
				<td><input type='text' name='MaintDuration05' /></td>
				<td><input type='text' name='MaintOPCode05' /></td>
			</tr>
			<tr>
				<td>06</td>
				<td>Replace Climate Control Air Filter</td>
				<td><input type='text' name='MaintPrice06' /></td>
				<td><input type='text' name='MaintDuration06' /></td>
				<td><input type='text' name='MaintOPCode06' /></td>
			</tr>
			<tr>
				<td>07</td>
				<td>Replace Coolant</td>
				<td><input type='text' name='MaintPrice07' /></td>
				<td><input type='text' name='MaintDuration07' /></td>
				<td><input type='text' name='MaintOPCode07' /></td>
			</tr>
			<tr>
				<td>08</td>
				<td>Replace Fuel Filter</td>
				<td><input type='text' name='MaintPrice08' /></td>
				<td><input type='text' name='MaintDuration08' /></td>
				<td><input type='text' name='MaintOPCode08' /></td>
			</tr>
			<tr>
				<td>09</td>
				<td>Replace Fuel Tank Air Filter</td>
				<td><input type='text' name='MaintPrice09' /></td>
				<td><input type='text' name='MaintDuration09' /></td>
				<td><input type='text' name='MaintOPCode09' /></td>
			</tr>
			<tr>
				<td>10</td>
				<td>Replace Rear Axle Fluid</td>
				<td><input type='text' name='MaintPrice10' /></td>
				<td><input type='text' name='MaintDuration10' /></td>
				<td><input type='text' name='MaintOPCode10' /></td>
			</tr>
			<tr>
				<td>11</td>
				<td>Replace Spark Plugs</td>
				<td><input type='text' name='MaintPrice11' /></td>
				<td><input type='text' name='MaintDuration11' /></td>
				<td><input type='text' name='MaintOPCode11' /></td>
			</tr>
			<tr>
				<td>12</td>
				<td>Tire Rotation</td>
				<td><input type='text' name='MaintPrice12' /></td>
				<td><input type='text' name='MaintDuration12' /></td>
				<td><input type='text' name='MaintOPCode12' /></td>
			</tr>
			<tr>
				<td>13</td>
				<td>Replace Wiper Blades</td>
				<td><input type='text' name='MaintPrice13' /></td>
				<td><input type='text' name='MaintDuration13' /></td>
				<td><input type='text' name='MaintOPCode13' /></td>
			</tr>
			<tr>
				<td>14</td>
				<td>Brake System Fluid Replacement</td>
				<td><input type='text' name='MaintPrice14' /></td>
				<td><input type='text' name='MaintDuration14' /></td>
				<td><input type='text' name='MaintOPCode14' /></td>
			</tr>
			<tr>
				<td>15</td>
				<td>Replace Spark Plugs (Iridium)</td>
				<td><input type='text' name='MaintPrice15' /></td>
				<td><input type='text' name='MaintDuration15' /></td>
				<td><input type='text' name='MaintOPCode15' /></td>
			</tr>
			<tr>
				<td>16</td>
				<td>Air Conditioning Service</td>
				<td><input type='text' name='MaintPrice16' /></td>
				<td><input type='text' name='MaintDuration16' /></td>
				<td><input type='text' name='MaintOPCode16' /></td>
			</tr>
		</table>

		<br /><br />
		<table border='1'>
			<col class="column-one">
	        <col class="column-two">
	        <col class="column-three">
	        <col class="column-four">
	        <col class="column-five">
			
			<tr>
				<th></th>
				<th>Repair Services</th>
				<th>Price</th>
				<th>Shop Duration Time</th>
				<th>OP Code</th>
			</tr>

			<tr>
				<td>01</td>
				<td>ABS Light Diagnosis</td>
				<td><input type='text' name='RepairPrice01' /></td>
				<td><input type='text' name='RepairDuration01' /></td>
				<td><input type='text' name='RepairOPCode01' /></td>
			</tr>		
			<tr>
				<td>02</td>
				<td>Body Appearance and/or Paint Concern</td>
				<td><input type='text' name='RepairPrice02' /></td>
				<td><input type='text' name='RepairDuration02' /></td>
				<td><input type='text' name='RepairOPCode02' /></td>
			</tr>
			<tr>
				<td>03</td>
				<td>Brake System Diagnosis</td>
				<td><input type='text' name='RepairPrice03' /></td>
				<td><input type='text' name='RepairDuration03' /></td>
				<td><input type='text' name='RepairOPCode03' /></td>
			</tr>		
			<tr>
				<td>04</td>
				<td>Check Engine Light Diagnosis</td>
				<td><input type='text' name='RepairPrice04' /></td>
				<td><input type='text' name='RepairDuration04' /></td>
				<td><input type='text' name='RepairOPCode04' /></td>
			</tr>		
			<tr>
				<td>05</td>
				<td>Electrical System Diagnosis</td>
				<td><input type='text' name='RepairPrice05' /></td>
				<td><input type='text' name='RepairDuration05' /></td>
				<td><input type='text' name='RepairOPCode05' /></td>
			</tr>		
			<tr>
				<td>06</td>
				<td>Engine Diagnosis (Noise, Leaks, Other)</td>
				<td><input type='text' name='RepairPrice06' /></td>
				<td><input type='text' name='RepairDuration06' /></td>
				<td><input type='text' name='RepairOPCode06' /></td>
			</tr>		
			<tr>
				<td>07</td>
				<td>Engine Performance Diagnosis (Running Rough, Other)</td>
				<td><input type='text' name='RepairPrice07' /></td>
				<td><input type='text' name='RepairDuration07' /></td>
				<td><input type='text' name='RepairOPCode07' /></td>
			</tr>		
			<tr>
				<td>08</td>
				<td>Heating or Air Conditioning Diagnosis</td>
				<td><input type='text' name='RepairPrice08' /></td>
				<td><input type='text' name='RepairDuration08' /></td>
				<td><input type='text' name='RepairOPCode08' /></td>
			</tr>		
			<tr>
				<td>09</td>
				<td>Squeaks & Rattles Diagnosis</td>
				<td><input type='text' name='RepairPrice09' /></td>
				<td><input type='text' name='RepairDuration09' /></td>
				<td><input type='text' name='RepairOPCode09' /></td>
			</tr>		
			<tr>
				<td>10</td>
				<td>Steering Diagnosis</td>
				<td><input type='text' name='RepairPrice10' /></td>
				<td><input type='text' name='RepairDuration10' /></td>
				<td><input type='text' name='RepairOPCode10' /></td>
			</tr>		
			<tr>
				<td>11</td>
				<td>Suspension Diagnosis</td>
				<td><input type='text' name='RepairPrice11' /></td>
				<td><input type='text' name='RepairDuration11' /></td>
				<td><input type='text' name='RepairOPCode11' /></td>
			</tr>		
			<tr>
				<td>12</td>
				<td>Transmission Diagnosis (Not Shifting Properly, Leaks, Other)</td>
				<td><input type='text' name='RepairPrice12' /></td>
				<td><input type='text' name='RepairDuration12' /></td>
				<td><input type='text' name='RepairOPCode12' /></td>
			</tr>		
			<tr>
				<td>13</td>
				<td>Trim or Moulding Diagnosis</td>
				<td><input type='text' name='RepairPrice13' /></td>
				<td><input type='text' name='RepairDuration13' /></td>
				<td><input type='text' name='RepairOPCode13' /></td>
			</tr>		
			<tr>
				<td>14</td>
				<td>Battery Concern</td>
				<td><input type='text' name='RepairPrice14' /></td>
				<td><input type='text' name='RepairDuration14' /></td>
				<td><input type='text' name='RepairOPCode14' /></td>
			</tr>		
			<tr>
				<td>15</td>
				<td>Light/Bulb Concern</td>
				<td><input type='text' name='RepairPrice15' /></td>
				<td><input type='text' name='RepairDuration15' /></td>
				<td><input type='text' name='RepairOPCode15' /></td>
			</tr>		
			<tr>
				<td>16</td>
				<td>Interior Body or Trim</td>
				<td><input type='text' name='RepairPrice16' /></td>
				<td><input type='text' name='RepairDuration16' /></td>
				<td><input type='text' name='RepairOPCode16' /></td>
			</tr>		
			<tr>
				<td>17</td>
				<td>Audio Diagnosis</td>
				<td><input type='text' name='RepairPrice17' /></td>
				<td><input type='text' name='RepairDuration17' /></td>
				<td><input type='text' name='RepairOPCode17' /></td>
			</tr>		
			<tr>
				<td>18</td>
				<td>Axle, Differential, Drivetrain Diagnosis</td>
				<td><input type='text' name='RepairPrice18' /></td>
				<td><input type='text' name='RepairDuration18' /></td>
				<td><input type='text' name='RepairOPCode18' /></td>
			</tr>		
			<tr>
				<td>19</td>
				<td>Engine Cooling Concern</td>
				<td><input type='text' name='RepairPrice19' /></td>
				<td><input type='text' name='RepairDuration19' /></td>
				<td><input type='text' name='RepairOPCode19' /></td>
			</tr>		
			<tr>
				<td>20</td>
				<td>Muffler/Exhaust System Diagnosis</td>
				<td><input type='text' name='RepairPrice20' /></td>
				<td><input type='text' name='RepairDuration20' /></td>
				<td><input type='text' name='RepairOPCode20' /></td>
			</tr>		
			<tr>
				<td>21</td>
				<td>SRS/Airbag Diagnosis</td>
				<td><input type='text' name='RepairPrice21' /></td>
				<td><input type='text' name='RepairDuration21' /></td>
				<td><input type='text' name='RepairOPCode21' /></td>
			</tr>		
		</table>
		
	</form>
</body>
</html>

Open in new window

0
Comment
Question by:UniqueData
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 35

Expert Comment

by:Kimputer
ID: 40502124
Sadly, I tested your code and it's working fine. Calling/navigating to the file does nothing of course (as per your own directive), but submitting does work as expected.

Usually I do this with the code when trying to figure out what's wrong:

<?php 
		$errMessage='test';
		echo  $_POST["sendMessage"] . $_POST["DealerCode"];
		
        if ( !empty($_POST["sendMessage"])  )
        {		echo "inside if loop1";
        		if ( empty($_POST["DealerCode"])) {  
					echo "inside if loop2";
    				$errMessage = 'You must enter a Dealer Code' ;
				} else {
					echo "inside if loop3";
					$errMessage='';
					$message = 'test';        		
					/*		
					$message = '';
					foreach($_POST as $key => $value)
					{
					    $message .= $key . ': ' . $value . "<br/>";
					} 
					*/       	
		            // To send HTML mail, the Content-type header must be set
		            $headers  = 'MIME-Version: 1.0' . "\r\n";
		            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		            $headers .= 'From: dealer submission <test@test.biz>' . "\r\n";
		            mail('test@yahoo.com','Message from Website',$message,$headers);

		        // MESSAGE SENT
		            header("Location: messageSent.php");
		            exit;                   
        		}
        }
?>

Open in new window


However, in this case it didn't help for me, as it worked as it should. So in essence, I saw all the echo which I wanted to see, when they were expected.

What PHP version is running on the server?
0
 
LVL 7

Author Comment

by:UniqueData
ID: 40502142
Odd thing is I have another page on the same server (I use Surpass Hosting) that works just fine, in fact the code I posted came from that other working page originally.  

I tried your echo technique.  The only thing that seemed to work was:  echo  $_POST["sendMessage"] . $_POST["DealerCode"];

however, it just seemed to only echo the DealerCode.   should I have seen 'True' or something like that for Post["sendMessage"] ?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40502171
I use this simple program to see all of the values that are submitted from a POST form.  I call it 'postdump.php'.  Substitute it for the 'action' page in your form to see everything you are sending.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>POST Dump</title>
</head>
<body>
<pre>
<?php 
var_dump($_POST);
foreach($_POST as $key => $value) {
    echo $key.' = '.$value."<br>";
}

?>
</pre>
</body>
</html>

Open in new window

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 35

Expert Comment

by:Kimputer
ID: 40502197
When page is loaded (without submit, just navigating) = $_POST["sendMessage"] = empty
When page is submitted to itself = $_POST["sendMessage"] = Submit

Therefore I think you use another php file to post it? Check the  submit code there is the same as this file (as this file is theoratically correctly coded).
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 250 total points
ID: 40502256
Maybe it's a difference in browser functionality, for me (in FireFox Dev) it stays empty also after submitting the page by pressing the button.

You can make sure you get something in the POST field by adding a value attribute on the button:
		<table width='85%'>
			<tr>
				<td>Dealer Code:<input type='text' name='DealerCode' /></td>
				<td><span class="error"><?php echo $errMessage;?></span></td>
				<td><button type="submit" class="btn btn-success" name="sendMessage" value="Submit">Submit</button></td>
			</tr>
		</table>

Open in new window

0
 
LVL 35

Expert Comment

by:Kimputer
ID: 40502261
Good catch, that is definitely the solution.
0
 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 250 total points
ID: 40502266
Currently your Submit doesn't have a value so when you submit your form, POST['sendMessage] will be empty and your if statement will skip over everything. Either give your button a value or change your if statement to use isset instead:

<button type="submit" class="btn btn-success" name="sendMessage" value="submit">Submit</button>

OR

isset($_POST["sendMessage"])
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40502380
When you're not sure what a variable contains, var_dump() is your friend.

If you want to see the POST-method request variables, use var_dump($_POST);

This may be a useful reference:
http://php.net/manual/en/language.variables.external.php
0
 
LVL 7

Author Closing Comment

by:UniqueData
ID: 40504093
That was it.  I forgot the value='submit'.

thought it was something simple :)

Thanks
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question