Jump to content

Recommended Posts

Ok, I have been creating this estimate form, and the processing code all day.

I am new to php, and I'll just bet I have a lot of mistakes in here.

I used a tutorial, and understood most all of it.

 

Screwy things are happening, such as upon hitting the submit button, all the php code prints on the next page instead of processing it.

 

Please explain what is wrong, or how I may make it better.

 

I just want to learn and learn it right.

 

Thanks ahead.

 

Form page:

<html>
<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link type="text/css" rel="stylesheet" href="css/estimate_form.css"/>
</head>
<body style="background: #efe5d0" >
<div id="container" style="	margin-left:200px; margin-right:auto;">

<form method="post" action="/estimate_processTest.php" target="_blank" >

	<fieldset style="text-align:right; width:500px">
				<legend>Contact Info</legend> 
  				
    				Full Name<input type="text" name="name" size="35"><br />    			
  					Email Address<input type="text" name="email" size="35"><br />
				Home Phone<input type="text" name="homePhone" size="35"><br />
				Business Phone<input type="text" name="businessPhone" size="35"><br />
			    Best time to contact you<input type="radio" name="bestTimeToContact" value="AM">
		            AM  			         
		            <input type="radio" name="Best time to contact you is" value="PM">
	            	PM 			
					<input type="radio" name="Best time to contact you is" value="Anytime">
					Anytime<br />
				Prefered Methods of Contact (Check all that apply)<br />
			            <input type="checkbox" name="contactBy" value="Home Phone">Home Phone  
			            <input type="checkbox" name="contactBy" value="Business Phone">Business Phone
			            <input type="checkbox" name="contactBy" value="Email">Email

	</fieldset>
	<br />
	<fieldset style="text-align:right; width:500px">
				<legend>Pickup Info</legend>
				City<input type="text" name="pickupCity" size="35"><br />
				State <select name="pickupState" size="1">
		              <option value="" selected>--Choose State--</option>
		              <option>AK</option>
		              <option>AL</option>
		              <option>AR</option>
		              <option>AZ</option>
		              <option>CA</option>
		              <option>CO</option>
		              <option>CT</option>
		              <option>DC</option>
		              <option>DE</option>
		              <option>FL</option>
		              <option>GA</option>
		              <option>HI</option>
		              <option>IA</option>
		              <option>ID</option>
		              <option>IL</option>
		              <option>IN</option>
		              <option>KS</option>
		              <option>KY</option>
		              <option>LA</option>
		              <option>MA</option>
		              <option>MD</option>
		              <option>ME</option>
		              <option>MI</option>
		              <option>MN</option>
		              <option>MO</option>
		              <option>MS</option>
		              <option>MT</option>
		              <option>NC</option>
		              <option>ND</option>
		              <option>NE</option>
		              <option>NH</option>
		              <option>NJ</option>
		              <option>NM</option>
		              <option>NV</option>
		              <option>NY</option>
		              <option>OH</option>
		              <option>OK</option>
		              <option>OR</option>
		              <option>PA</option>
		              <option>RI</option>
		              <option>SC</option>
		              <option>SD</option>
		              <option>TN</option>
		              <option>TX</option>
		              <option>UT</option>
		              <option>VA</option>
		              <option>VI</option>
		              <option>VT</option>
		              <option>WA</option>
		              <option>WI</option>
		              <option>WV</option>
		              <option>WY</option>
		              <option>NONE</option>
		            </select><br />
					Zip Code
			            <input type="text" name="pickupZip" size="12">
		</fieldset>	
			<br />
		<fieldset style="text-align:right; width:500px">
			<legend>Destination Info</legend>
				City<input type="text" name="destinationCity" size="35"><br />
				State <select name="destinationState" size="1">
		              <option value="" selected>--Choose State--</option>
		              <option>AK</option>
		              <option>AL</option>
		              <option>AR</option>
		              <option>AZ</option>
		              <option>CA</option>
		              <option>CO</option>
		              <option>CT</option>
		              <option>DC</option>
		              <option>DE</option>
		              <option>FL</option>
		              <option>GA</option>
		              <option>HI</option>
		              <option>IA</option>
		              <option>ID</option>
		              <option>IL</option>
		              <option>IN</option>
		              <option>KS</option>
		              <option>KY</option>
		              <option>LA</option>
		              <option>MA</option>
		              <option>MD</option>
		              <option>ME</option>
		              <option>MI</option>
		              <option>MN</option>
		              <option>MO</option>
		              <option>MS</option>
		              <option>MT</option>
		              <option>NC</option>
		              <option>ND</option>
		              <option>NE</option>
		              <option>NH</option>
		              <option>NJ</option>
		              <option>NM</option>
		              <option>NV</option>
		              <option>NY</option>
		              <option>OH</option>
		              <option>OK</option>
		              <option>OR</option>
		              <option>PA</option>
		              <option>RI</option>
		              <option>SC</option>
		              <option>SD</option>
		              <option>TN</option>
		              <option>TX</option>
		              <option>UT</option>
		              <option>VA</option>
		              <option>VI</option>
		              <option>VT</option>
		              <option>WA</option>
		              <option>WI</option>
		              <option>WV</option>
		              <option>WY</option>
		              <option>NONE</option>
		            </select><br />
					Zip Code
			            <input type="text" name="destinationZip" size="12">							
		</fieldset>
			<br />
		<fieldset style="text-align:right; width:500px">
			<legend>Moving Date</legend>
				<select name="moveMonth" class="inputBox" id="MoveMonth" onChange="setMonthDays()">
	              <option value="0" selected>Month      </option>
	              <option value="1">Jan</option>
	              <option value="2">Feb</option>
	              <option value="3">Mar</option>
	              <option value="4">Apr</option>
	              <option value="5">May</option>
	              <option value="6">Jun</option>
	              <option value="7">Jul</option>
	              <option value="8">Aug</option>
	              <option value="9">Sep</option>
	              <option value="10">Oct</option>
	              <option value="11">Nov</option>
	              <option value="12">Dec</option>
	            </select>
	            <select name="moveDay" class="inputBox" id="MoveDay" >
	              <OPTION value="0" selected>Day  </OPTION>
	              <OPTION value=1>1</OPTION>
	              <OPTION value=2>2</OPTION>
	              <OPTION value=3>3</OPTION>
	              <OPTION value=4>4</OPTION>
	              <OPTION value=5>5</OPTION>
	              <OPTION value=6>6</OPTION>
	              <OPTION value=7>7</OPTION>
	              <OPTION value=8>8</OPTION>
	              <OPTION value=9>9</OPTION>
	              <OPTION value=10>10</OPTION>
	              <OPTION value=11>11</OPTION>
	              <OPTION value=12>12</OPTION>
	              <OPTION value=13>13</OPTION>
	              <OPTION value=14>14</OPTION>
	              <OPTION value=15>15</OPTION>
	              <OPTION value=16>16</OPTION>
	              <OPTION value=17>17</OPTION>
	              <OPTION value=18>18</OPTION>
	              <OPTION value=19>19</OPTION>
	              <OPTION value=20>20</OPTION>
	              <OPTION value=21>21</OPTION>
	              <OPTION value=22>22</OPTION>
	              <OPTION value=23>23</OPTION>
	              <OPTION value=24>24</OPTION>
	              <OPTION value=25>25</OPTION>
	              <OPTION value=26>26</OPTION>
	              <OPTION value=27>27</OPTION>
	              <OPTION value=28>28</OPTION>
	              <OPTION value=29>29</OPTION>
	              <OPTION value=30>30</OPTION>
	              <OPTION value=31>31</OPTION>
	            </SELECT>
	            <select name="moveYear" class="inputBox" id="MoveYear" >
	              <OPTION value="0" selected>Year  </OPTION>
	              <OPTION value=2007>2008</OPTION>
	              <OPTION value=2008>2009</OPTION>
	            </SELECT><br />

	</fieldset>
	<br />
	<fieldset style="text-align:right; width:500px">
		<legend>Size of Move</legend>
			Estimated Weight. (If Known)<input type="text" name="estimateWeight" size="35"><br />
			Number of Furnished Rooms<input type="text" name="numberFurnishedRooms" size="4">
	</fieldset>
	<br />
	<fieldset style="text-align:right; width:500px">
		<legend>Other Comments or Requests</legend>
			<textarea name="otherCommentsOrRequests" cols="40" rows="2"></textarea>
	</fieldset>
	<br />
	<fieldset style="text-align:right; width:500px">
		<legend>Submit Estimate Request Form</legend>
	<input type="submit" value="Send Information" style="float:right;">	
</form>		
</div>  
</body>
</html>

 

Processing page:

?php
error_reporting(E_ALL);

/* Set e-mail recipient */
$myemail  = "myemail@somewhere.com";

/* Check all form inputs using check_input function */
$name = check_input($_POST['name'] , "Enter your name");
$email = check_input($_POST['email'] , "Enter your email");
$homePhone = $_POST['homePhone'];
$businessPhone = $_POST['businessPhone'];
$bestTimeToContact = $_POST['bestTimeToContact'];
$contactBy = $_POST['contactBy'];

$pickupCity = $_POST['pickupCity'];
$pickupState = $_POST['pickupState'];
$pickupZip = $_POST['pickupZip'];

$destinationCity = $_POST['destinationCity'];
$destinationState = $_POST['destinationState'];
$destinationZip = $_POST['destinationZip'];

$moveMonth = $_POST['moveMonth'];
$moveDay = $_POST['moveDay'];
$moveYear = $_POST['moveYear'];

$estimateWeight = $_POST['estimateWeight'];
$numberFurnishedRooms = $_POST['numberFurnishedRooms'];

$otherCommentsOrRequests = $_POST['otherCommentsOrRequests'];


/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "Moving Solutions

Your contact form has been submitted by:

Name: $name
E-mail: $email

Home Phone: $homePhone
Business Phone: $businessPhone


The best time to contact $name is $bestTimeToContact 
$name wishes to be contacted by $contactBy

Moving from:
$pickupCity 
$pickupState
$pickupZip

Moving to:
$destinationCity 
$destinationState 
$destinationZip 

Estimated Weight: $estimateWeight
Number of Furnished Rooms: $numberFurnishedRooms

Other Comments or Requests: $otherCommentsOrRequests
End of message
";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: estimate_redirect.htm');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}
function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php
exit();
}
?>

 

The browser did not like that last curley brace either.  Then when I took that out what I got

was all the php code in the browser instead of the thank you page.

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/121620-solved-estimate-request-form/
Share on other sites

Bingo!  Thanks.

 

Now brings me to something I did not understand and I get an error on it also...

 

at the end of the processing page they end the php in order to print an error message.

I haven't seen this before and would like to understand.

 

The browser says

unexpected $end, which is the last closing php tag. ?>

 

 

 

Right again!  When I put it back in it now works.

 

I have a question about the from field in my inbox.

This submission said the email was from a weird email address...

 

It had the first part of my email right, but after the @ it says pro36.abac.com

 

Any ideas why it would do that?

 

How could I possibly do it differently if necessary?

 

Thanks so much.

Right again!  When I put it back in it now works.

 

I have a question about the from field in my inbox.

This submission said the email was from a weird email address...

 

It had the first part of my email right, but after the @ it says pro36.abac.com

 

Any ideas why it would do that?

 

How could I possibly do it differently if necessary?

 

Thanks so much.

 

Make the header something like:

From: DarkWater <email@email.com>

 

Just use what you want in the proper places, lol.

Ok DarkWater i feel really stupid asking this question, but

what do you mean when you say to change the header?

 

My only header redirects the user to the thank you page...

 

So where do I put From: Name<email@email.com>

 

And would you explain this header your teaching me about and how

it will end up being in my from column in my inbox. 

 

I am very challenged when it comes to php.  But I love it!

 

Thanks for everything.

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.