By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

Making an order form for a pizza company

P: 2
I finished an order form for a pizza company. It works but they want me to implement some math into it. I am unsure how to go about this, and am hoping I don't have to rewrite the entire form and php.

Form
Expand|Select|Wrap|Line Numbers
  1. <form name="Pizza" method="post" action="formsent.php">
  2.                     <div class="row">
  3.                         <p>
  4.                             <label>Your Name</label>
  5.                             <input type="text" name="name" class="text_field" />
  6.                         </p>
  7.                         <p>
  8.                             <label>Your Email</label>
  9.                             <input type="text" name="email" class="text_field" />
  10.                         </p>
  11.                     </div>
  12.                     <div class="row">
  13.                         <p>
  14.                             <label>Your Phone Number</label>
  15.                             <input type="text" name="phone" class="text_field" />
  16.                         </p>
  17.                                                 <p>
  18.                             <label>Your Address</label>
  19.                             <input type="text" name="address" class="text_field" />
  20.                         </p>
  21.                         <!-- <p>
  22.                             <label>Subject</label>
  23.                             <select class="text_field" name="subject">
  24.                                 <option>Select a subject...</option>
  25.                                 <option>Option 2</option>
  26.                             </select> -->
  27.                         </p>
  28.                     </div>
  29.                     <label>Size of Pizza  Type of Crust  Pre-Packaged Special or Gourmet Pizza</label>
  30. <SELECT NAME="size">
  31. <OPTION>Medium
  32. <OPTION>Large
  33. <OPTION>Extra Large
  34. </SELECT>
  35.  
  36. <SELECT NAME="crust">
  37. <OPTION>Regular Crust
  38. <OPTION>Thick Crust
  39. </SELECT>
  40.  
  41. <SELECT NAME="type">
  42. <OPTION>Other Items; No Pizza
  43. <OPTION>Create Your Own
  44. <OPTION>Combination
  45. <OPTION>Margarita
  46. <OPTION>Canadian
  47. <OPTION>Hawaiian
  48. <OPTION>Vegetarian
  49. <OPTION>Mexican
  50. <OPTION>Meat Lovers
  51. <OPTION>Greek
  52. <OPTION>Chicken Fajita
  53. <OPTION>Vege Extreme
  54. <OPTION>Michael's Original
  55. <OPTION>Mediterranean
  56. </SELECT>
  57. <div align="left">
  58. <b>Create your Own Toppings</b><br>
  59. <INPUT TYPE="checkbox" NAME="topping1" VALUE="Pepperoni">             Pepperoni <br>   
  60. <INPUT TYPE="checkbox" NAME="topping2" VALUE="Salami">               Salami <br>        
  61. <INPUT TYPE="checkbox" NAME="topping3" VALUE="Canadian Style Bacon">    Canadian Style Bacon <br>
  62. <INPUT TYPE="checkbox" NAME="topping4" VALUE="Fresh Mushrooms">         Fresh Mushrooms<br>
  63. <INPUT TYPE="checkbox" NAME="topping5" VALUE="Black Olives">            Black Olives <br>  
  64. <INPUT TYPE="checkbox" NAME="topping6" VALUE="Green Peppers">         Green Peppers<br> 
  65. <INPUT TYPE="checkbox" NAME="topping7" VALUE="Ground Beef">             Ground Beef <br>   
  66. <INPUT TYPE="checkbox" NAME="topping8" VALUE="Italian Sausage">         Italian Sausage <br> 
  67. <INPUT TYPE="checkbox" NAME="topping9" VALUE="Fresh Tomatoes">           Fresh Tomatoes <br> 
  68. <INPUT TYPE="checkbox" NAME="topping10" VALUE="Onions">                     Onions <br>
  69. <INPUT TYPE="checkbox" NAME="topping11" VALUE="Pineapple">               Pineapple <br> 
  70. <INPUT TYPE="checkbox" NAME="topping12" VALUE="Jalapeno Peppers">          Jalapeno Peppers<br>
  71. <INPUT TYPE="checkbox" NAME="topping13" VALUE="Anchovies">               Anchovies <br>    
  72. <INPUT TYPE="checkbox" NAME="topping14" VALUE="Extra Cheese">         Extra Cheese<br> 
  73. </div>
  74. <Label> Appetizers</Label>
  75. <SELECT NAME="apps">
  76. <OPTION>None
  77. <OPTION>Wedges
  78. <OPTION>Seasoned Fries
  79. <OPTION>Poutine (Large)
  80. <OPTION>Poutine (Small)
  81. <OPTION>Onion Rings
  82. <OPTION>Mozzerella Sticks
  83. <OPTION>Garlic Bread
  84. <OPTION>Garlic Bread with Cheese
  85. <OPTION>Macaroni Salad
  86. <OPTION>Soup
  87. </SELECT>
  88. <br />
  89. <label>Salads</label>
  90. <SELECT NAME="salad">
  91. <OPTION>None
  92. <OPTION>Garden Salad
  93. <OPTION>Greek Salad
  94. <OPTION>Mediterranean Greek Salad
  95. <OPTION>Caesar Salad
  96. <OPTION>Chef Salad
  97. </SELECT>
  98. <br /><label>Baked Pockets</label>
  99. <SELECT NAME="pocket">
  100. <OPTION>None
  101. <OPTION>Spinach &amp; Feta Pocket
  102. <OPTION>Mediterranean Pocket
  103. <OPTION>Greek Pocket
  104. <OPTION>Steak Pocket
  105. <OPTION>Club Pocket
  106. <OPTION>Veggie Pocket
  107. <OPTION>Deli Pocket
  108. <OPTION>Build Your Own Pocket ($1/extra topping)
  109. </SELECT>
  110. <br /><label>Fried Chicken</label>
  111. <SELECT NAME="chicken">
  112. <OPTION>None
  113. <OPTION>2 piece Dinner
  114. <OPTION>3 piece Dinner
  115. <OPTION>4 piece Dinner
  116. <OPTION>3 piece Chicken
  117. <OPTION>6 piece Chicken
  118. <OPTION>9 piece Chicken
  119. <OPTION>12 piece Chicken
  120. </SELECT>
  121. <br /><label>Chicken Wings</label>
  122. <SELECT NAME="wings">
  123. <OPTION>None
  124. <OPTION>10 wings
  125. <OPTION>20 wings
  126. <OPTION>30 wings
  127. </SELECT>
  128. <SELECT NAME="sauce">
  129. <OPTION>No Sauce
  130. <OPTION>Hot Sauce
  131. <OPTION>Mild Sauce
  132. <OPTION>Honey Garlic
  133. <OPTION>BBQ Sauce
  134. </SELECT>
  135. <br /><label>Burgers</label>
  136. <SELECT NAME="burgers">
  137. <OPTION>No Burger
  138. <OPTION>Sirloin Burger
  139. <OPTION>Pizza Burger
  140. <OPTION>Bacon Cheese Burger
  141. <OPTION>Chicken Burger
  142. <OPTION>The Ringer
  143. <OPTION>Swiss Burger
  144. <OPTION>Firehouse Burger
  145. <OPTION>Sliders
  146. </SELECT>
  147. <br /><Label>Toasted Subs</Label>
  148. <SELECT NAME="subs">
  149. <OPTION>No Sub
  150. <OPTION>Deluxe
  151. <OPTION>Chicken Club
  152. <OPTION>Steak Sub
  153. <OPTION>BBQ Chicken
  154. <OPTION>Pizza Sub
  155. <OPTION>Gyro Sub
  156. </SELECT>
  157. <br /><Label>Desserts</Label>
  158. <SELECT NAME="dessert">
  159. <OPTION>None
  160. <OPTION>Brownies
  161. <OPTION>Cheesecake
  162. <OPTION>Fried Sugar Doughballs
  163. </SELECT>
  164.                     <p>
  165.                         <label>Additional Input</label>
  166.                         <textarea class="text_field" rows="10" cols="10" name="info"></textarea>
  167.                     </p>
  168.                     <input type="submit" class="button" value="Send Message" />
  169.                 </form>
PHP
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['email'])) {
  3.  
  4.     // EDIT THE 2 LINES BELOW AS REQUIRED
  5.     $email_to = "order@slicesandsquares.com";
  6.     $email_subject = "Pizza Order";
  7.  
  8.         function died($error) {
  9.         // your error code can go here
  10.         echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  11.         echo "These errors appear below.<br /><br />";
  12.         echo $error."<br /><br />";
  13.         echo "Please go back and fix these errors.<br /><br />";
  14.         die();
  15.     }
  16.     // validation expected data exists
  17.     if(!isset($_POST['name']) ||
  18.         !isset($_POST['address']) ||
  19.         !isset($_POST['size']) ||
  20.         !isset($_POST['crust']) ||
  21.         !isset($_POST['type']) ||
  22.         !isset($_POST['phone'])){
  23.         died('We are sorry, but there appears to be a problem with the form you submitted.');       
  24.     }
  25.  
  26.     $first_name = $_POST['name']; // required
  27.     $email_from = $_POST['address']; // required
  28.     $comments = $_POST['phone']; // required
  29.     $size = $_POST['size']; // required
  30.     $crust = $_POST['crust']; // required
  31.     $type = $_POST['type']; // required
  32.     $t1 = $_POST['topping1']; // required
  33.     $t2 = $_POST['topping2']; // required
  34.     $t3 = $_POST['topping3']; // required
  35.     $t4 = $_POST['topping4']; // required
  36.     $t5 = $_POST['topping5']; // required
  37.     $t6 = $_POST['topping6']; // required
  38.     $t7 = $_POST['topping7']; // required
  39.     $t8 = $_POST['topping8']; // required
  40.     $t9 = $_POST['topping9']; // required
  41.     $t10 = $_POST['topping10']; // required
  42.     $t11 = $_POST['topping11']; // required
  43.     $t12 = $_POST['topping12']; // required
  44.     $t13 = $_POST['topping13']; // required
  45.     $t14 = $_POST['topping14']; // required
  46.     $apps = $_POST['apps']; // required
  47.     $salad = $_POST['salad']; // required
  48.     $pocket = $_POST['pocket']; // required
  49.     $chicken = $_POST['chicken']; // required
  50.     $wings = $_POST['wings']; // required
  51.     $sauce = $_POST['sauce']; // required
  52.     $burgers = $_POST['burgers']; // required
  53.     $subs = $_POST['subs']; // required
  54.     $dessert = $_POST['dessert']; // required
  55.     $info = $_POST['info']; // required
  56.  
  57.     // $error_message = "";
  58.     // $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  59.   // if(!preg_match($email_exp,$email_from)) {
  60.    //  $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  61.   // }
  62.     $string_exp = "/^[A-Za-z .'-]+$/";
  63.   if(!preg_match($string_exp,$first_name)) {
  64.     $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  65.   }
  66.   if(strlen($comments) < 2) {
  67.     $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  68.   }
  69.   if(strlen($error_message) > 0) {
  70.     died($error_message);
  71.   }
  72.     $email_message = "Form details below.\n\n";
  73.  
  74.     function clean_string($string) {
  75.       $bad = array("content-type","bcc:","to:","cc:","href");
  76.       return str_replace($bad,"",$string);
  77.     }
  78.  
  79.     $email_message .= "name: ".clean_string($first_name)."\n";
  80.     $email_message .= "address: ".clean_string($email_from)."\n";
  81.     $email_message .= "phone: ".clean_string($comments)."\n";
  82.     $email_message .= "size: ".clean_string($size)."\n";
  83.     $email_message .= "crust: ".clean_string($crust)."\n";
  84.     $email_message .= "type: ".clean_string($type)."\n";
  85.     $email_message .= "topping1: ".clean_string($t1)."\n";
  86.     $email_message .= "topping2: ".clean_string($t2)."\n";
  87.     $email_message .= "topping3: ".clean_string($t3)."\n";
  88.     $email_message .= "topping4: ".clean_string($t4)."\n";
  89.     $email_message .= "topping5: ".clean_string($t5)."\n";
  90.     $email_message .= "topping6: ".clean_string($t6)."\n";
  91.     $email_message .= "topping7: ".clean_string($t7)."\n";
  92.     $email_message .= "topping8: ".clean_string($t8)."\n";
  93.     $email_message .= "topping9: ".clean_string($t9)."\n";
  94.     $email_message .= "topping10: ".clean_string($t10)."\n";
  95.     $email_message .= "topping11: ".clean_string($t11)."\n";
  96.     $email_message .= "topping12: ".clean_string($t12)."\n";
  97.     $email_message .= "topping13: ".clean_string($t13)."\n";
  98.     $email_message .= "topping14: ".clean_string($t14)."\n";
  99.     $email_message .= "apps: ".clean_string($apps)."\n";
  100.     $email_message .= "salad: ".clean_string($salad)."\n";
  101.     $email_message .= "pocket: ".clean_string($pocket)."\n";
  102.     $email_message .= "chicken: ".clean_string($chicken)."\n";
  103.     $email_message .= "wings: ".clean_string($wings)."\n";
  104.     $email_message .= "sauce: ".clean_string($sauce)."\n";
  105.     $email_message .= "burgers: ".clean_string($burgers)."\n";
  106.     $email_message .= "subs: ".clean_string($subs)."\n";
  107.     $email_message .= "dessert: ".clean_string($dessert)."\n";
  108.     $email_message .= "info: ".clean_string($info)."\n";
  109.  
  110.  
  111. // create email headers
  112. $headers = 'From: '.$email_from."\r\n".
  113. 'Reply-To: '.$email_from."\r\n" .
  114. 'X-Mailer: PHP/' . phpversion();
  115. @mail($email_to, $email_subject, $email_message, $headers);  
  116. ?>
  117.  
  118. <!-- include your own success html here -->
  119.  
  120. Thank you for contacting us. We will be in touch with you very soon.
  121.  
  122. <?php
  123. }
  124. ?>
So basically I need to add a value to each of the items. I thought about just switching the drop boxes to check boxes and using php to do the math, but am uncertain how I would make it so only the checked boxes are calculated. If there is an easier way that would be greatly appreciated.
I will also have to add an if statement.
They want the total + tax and a delivery fee ($3.50) if the total is under $30 before taxes.

I am recently out of school and this is on the my first projects and its gotten a little confusing. Any help would be appreciated.

Thank you in advance.
Dec 20 '11 #1
Share this Question
Share on Google+
3 Replies


zorgi
Expert 100+
P: 431
"drop boxes to check boxes" ... why? Options within drop boxes can have values?
Dec 20 '11 #2

P: 2
Okay thanks. The only issue I have left is setting the toppings and specialty pizzas. They each would have 3 different values. (Small, Medium and Large) How would I go about doing that. I've been brainstorming and wondering if maybe I could have the options swap depending on which option I select (Small, Medium, Large) Perhaps lines of if, if else statements in the php. Or somehow using classes to select between the three options. Other than that, I have it set up. Thanks again.
Dec 22 '11 #3

P: 5
Let me know your issue excatly.
where you need to calculation
1)when user is ordering for pizza ?
or
2)when sending the mail ?
Dec 26 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.