Solved

form submit not working

Posted on 2014-12-15
9
143 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
9 Comments
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
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
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
 
LVL 35

Expert Comment

by:Kimputer
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 35

Accepted Solution

by:
Robert Schutt earned 250 total points
Comment Utility
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
Comment Utility
Good catch, that is definitely the solution.
0
 
LVL 42

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 250 total points
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
That was it.  I forgot the value='submit'.

thought it was something simple :)

Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now