Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript] [PHP] Formularz wyceny nie wysyła sumy POMOCY
zayor84
post 27.02.2010, 12:55:46
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 27.02.2010

Ostrzeżenie: (0%)
-----


Witam,

jestem kompletnym laikiem, a potrzebuję tego skryptu na stronę. Chodzi mi o wycenę zamówienia z możliwością wysłania do mnie na email.

Korzystając z innych for i źródeł skleciłem coś takiego:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html lang="pl">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Kalkulator</title>
  6. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  7. <script type="text/javascript">
  8. google.load("jquery", "1");
  9. </script>
  10. <script type="text/javascript">
  11. function update(){
  12. var sum = 0;
  13. $("#calculator > tbody > tr").each(function(){
  14. var price = parseFloat($(this).find("td:eq(2)").text());
  15. var amount = parseFloat($(this).find("td:eq(3)").find("input:first").val());
  16. var value = $(this).find("td:eq(4)");
  17. if (amount > 0) {
  18. value.text(price*amount);
  19. sum += price*amount;
  20. } else {
  21. value.text(0);
  22. }
  23. });
  24. $("#summary").text(sum);
  25. }
  26. $(document).ready(function(){
  27. update();
  28. $("#calculator input").keyup(function(){
  29. update();
  30. });
  31. });
  32. </script>
  33. </head>
  34. <body>
  35.  
  36.  
  37.  
  38. <?php
  39. if (count($_POST))
  40. {
  41. $email = 'adres@email.pl';
  42. $subject = 'Wycena';
  43. $message = 'Formularz wysłany';
  44. $error = 'Wystąpił błąd podczas wysyłania formularza';
  45. $charset = 'windows-1250';
  46.  
  47.  
  48. $head =
  49. "MIME-Version: 1.0\r\n" .
  50. "Content-Type: text/plain; charset=$charset\r\n" .
  51. "Content-Transfer-Encoding: 8bit";
  52. $body = '';
  53. foreach ($_POST as $name => $value)
  54. {
  55. if (is_array($value))
  56. {
  57. for ($i = 0; $i < count($value); $i++)
  58. {
  59. $body .= "$name=" . (get_magic_quotes_gpc() ? stripslashes($value[$i]) : $value[$i]) . "\r\n";
  60. }
  61. }
  62. else $body .= "$name=" . (get_magic_quotes_gpc() ? stripslashes($value) : $value) . "\r\n";
  63. }
  64. echo mail($email, "=?$charset?B?" . base64_encode($subject) . "?=", $body, $head) ? $message : $error;
  65. }
  66. else
  67. {
  68. ?>
  69.  
  70. <form action="?" method="post">
  71.  
  72.  
  73.  
  74. <b><font color="red">Kategoria 1:</font></b> <br>
  75. <table id="calculator">
  76. <tr>
  77. <th>Produkt:</th>
  78. <th>&nbsp;</th>
  79. <th>Cena</th>
  80. <th>Ilosc</th>
  81. <th>&nbsp;</th>
  82. </tr>
  83. </thead>
  84. <tr>
  85. <th colspan="4">Razem</th>
  86. <th id="summary"><input type="text" name="Razem[]" size="6"></th>
  87. </tr>
  88. </tfoot>
  89. <tr>
  90. <td>Produkt 1</td>
  91. <td>&nbsp;</td>
  92. <td>0.20</td>
  93. <td><input type="text" name="Produkt1[]" size="3"></td>
  94. <td></td>
  95. </tr>
  96. <tr>
  97. <td>Produkt 2</td>
  98. <td>&nbsp;</td>
  99. <td>0.40</td>
  100. <td><input type="text" name="Produkt2[]" size="3"></td>
  101. <td></td>
  102. </tr>
  103. <tr>
  104. <td>Produkt 3</td>
  105. <td>&nbsp;</td>
  106. <td>0.80</td>
  107. <td><input type="text" name="Produkt3[]" size="3"></td>
  108. <td></td>
  109. </tr>
  110. </tbody>
  111. </table>
  112. <input type="submit" value=" wyslij " / >
  113.  
  114. </form>
  115. <?php
  116. }
  117. ?>
  118.  
  119. </body>
  120. </html>
  121.  



Wszystko jest ok, ale nie w mailu ze strony nie ma danej Razem. Poza tym, nie wiem jak skrócić do dwóch miejsc po przecinku. Proszę o pomoc.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.07.2025 - 23:32