Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Problem z polami wymaganymi w formularzu.
adiscan
post
Post #1





Grupa: Zarejestrowani
Postów: 64
Pomógł: 0
Dołączył: 12.04.2007

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


Mam problem z polami wymaganymi! Tzn nie wiem jak zrobić żeby komunikat o nie wypełnionym polu na tej samej stronie i bez potrzeby wypełniania ponownie formularza.


Poniższy skrypt to robi ale ... widnieje cały czas napis o nie wypełnionym polu i jesli dam wyslij i nie wypełnie pola wymaganego to czyści mi cały formularz ... i nie umie sobie z tym poradzic

I nastepna sprawa to formatowanie tresci samej wiadomosci tzn zmiennej $message tak by były zachowane wszystkie znaki w sensie zeby ENTER był Enterem a nie tak jak jest teraz JEDEN WIELKI CIĄG znakow!

Bede wdzieczny za wszystkie rady.

Wszystko znajduje sie w jednym pliku test2.php tzn formularz w htmlu i mail() w php ...

Do pola wymaganego zastosowałem instr warunkową if ... else

Oj przepraszam za tak rozwalonego posta (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

  1. <?php
  2. if($name=='')
  3. {
  4. echo $error;
  5. }
  6. else
  7. {
  8. wykonaj skrypt
  9. }
  10. ?>


  1. <html>
  2.  
  3. <head>
  4. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
  5. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  6. <meta name="ProgId" content="FrontPage.Editor.Document">
  7. <title>Formularz Kontaktowy</title>
  8. </head>
  9.  
  10. <body>
  11.  
  12. <p align="center">
  13. <div align="right">
  14. <form action="http://www.tienspolska.com/ftp/test2.php" name="form" method="post">
  15.  <center>
  16. <table border="0" cellpadding="0" cellspacing="1" width="322" height="533" bgcolor="#EDFCE0" style="border: 0 double #008000">
  17. <tr>
  18. <td width="627" height="30" colspan="4" bordercolor="#00FFFF" bgcolor="#BCE184">
  19. <p align="center"><font color="#FFFFFF"><b>Formularz Kontaktowy</b></font> </td>
  20. </tr>
  21. <tr>
  22. <td width="193" height="40" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Imię i 
  23. Nazwisko:     </font> </td>
  24. <td width="759" colspan="3" height="40"> <input type="text" name="name" size="55"></td>
  25. </tr>
  26. <tr>
  27. <td width="193" height="25" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Ulica:</font></td>
  28. <td width="418" colspan="3" height="25"> <input type="text" name="ulica" size="55"></td>
  29. </tr>
  30. <tr>
  31. <td width="193" height="40" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Nr domu:</font></td>
  32. <td width="137" height="40"> <input type="text" name="numer" size="10"></td>
  33. <td width="198" height="40">
  34. <p align="center"><font face="Arial" size="2">Kod pocztowy:</font></td>
  35. </center>
  36. <td width="424" height="40">
  37. <p align="left"><input type="text" name="kod" size="14"></td>
  38. </tr>
  39. <center>
  40. <tr>
  41. <td width="193" height="26" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Miejscowość: </font> </td>
  42. <td width="759" colspan="3" height="26"> <input type="text" name="miejscowosc" size="55"></td>
  43. </tr>
  44. <tr>
  45. <td width="193" height="25" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Twoj Email:</font></td>
  46. <td width="759" colspan="3" height="25"> <input type="text" name="email" size="55"></td>
  47. </tr>
  48. <tr>
  49. <td width="193" height="40" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Jak mamy Ci
  50. odpowiedzieć?</font></td>
  51. <td width="759" colspan="3" height="40"> <select size="1" name="select">
  52. <option selected>E-mail zwrotny</option>
  53. <option>Telefonicznie                  
  54. </option>
  55. </select>   <font size="2" face="Arial">  nr tel.  </font><font size="1"> 
  56. </font><input type="text" name="tel" size="12"></td>
  57. </tr>
  58. <tr>
  59. <td width="193" height="40" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Temat
  60. wiadomoćci:             </font>
  61. </td>
  62. <td width="759" colspan="3" height="40"> <select size="1" name="subject">
  63. <option selected>Pytanie odnośnie produktów firmy Tiens</option>
  64. <option>Karta Klienta Firmy Tiens - informacje</option>
  65. <option>Zamówienie</option>
  66. <option>Reklamacje</option>
  67. <option>Inny</option>
  68.  
  69. </select></td>
  70. </tr>
  71. <tr>
  72. <td width="193" height="271" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Treść
  73. wiadomoćci:</font></td>
  74. <td width="759" colspan="3" height="271" style="border-top-style: double" bordercolor="#BCE184"><textarea rows="13" name="tresc" cols="50"></textarea></td>
  75. </tr>
  76. <tr>
  77. <td width="902" height="27" colspan="4" align="center" bgcolor="#BCE184">
  78. <input type="submit" value=" Wyślij  " style="border-style: double; border-color: #008000"></td>
  79. <input type="reset" value="reset">
  80. </tr>
  81. </table>
  82. </center>
  83. </div>
  84. <p align="left"> 
  85. <p align="left"> 
  86. <p align="left"><br>
  87. </p>
  88. </form>
  89.  
  90. </body>
  91.  
  92. </html>
  93.  
  94. <?php
  95. header("Content-type: text/html; charset=utf-8");
  96.  
  97.  
  98.  
  99. $name = $_POST['name'];
  100. $ulica = $_POST['ulica'];
  101. $numer = $_POST['numer'];
  102. $kod = $_POST['kod'];
  103. $miejscowosc = $_POST['miejscowosc'];
  104. $email = $_POST['email'];  //email tego kto ma pytanie
  105. $select = $_POST['select'];
  106. $tel = $_POST['tel'];
  107. $tresc = $_POST['tresc'];
  108. $error = "nie wszystkie pola są wypełnione";
  109.  
  110. /////////////////////////////////////////////////////////////
  111.  
  112.  
  113.  
  114.  
  115. if($name=='')
  116. {
  117.  
  118. echo $error;
  119.  
  120. }
  121. else
  122.  
  123. {
  124. //adresaci
  125. $do = " wiadomo ".",";
  126. $do .= " wiadomo ";
  127.  
  128. // temat maila
  129. $subject = $_POST['subject'];
  130.  
  131. // wiadomosc
  132.  
  133. $wiadomosc .= '
  134. <html>
  135. <head>
  136. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  137. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  138. <meta name="ProgId" content="FrontPage.Editor.Document">
  139. <title>Tytuł tej wiadomosci:</title>
  140. </head>
  141.  
  142. <body>
  143.  
  144.  
  145. <div align="left">
  146. <table border="0" cellpadding="0" cellspacing="1" width="528" height="158">
  147. <tr>
  148. <td width="155" height="20" align="left"><b>Imie i Nazwisko:</b></td>
  149. <td width="363" height="20" align="left">'.$name.'</td>
  150. </tr>
  151. <tr>
  152. <td width="155" height="21" align="left"><b>Adres:</b></td>
  153. <td align="left" width="359">'.$ulica.' '.$numer.'</td>
  154. </tr>
  155. <tr>
  156. <td width="155" height="21" align="left"></td>
  157. <td align="left" width="359">'.$kod.' '.$miejscowosc.'</td>
  158. </tr>
  159. <tr>
  160. <td width="155" height="19" align="left"><b>Kotnakt:</b></td>
  161. <td width="359" height="19" align="left">e-mail:  '.$email.'</td>
  162. </tr>
  163. <tr>
  164. <td width="155" height="21" align="left"></td>
  165. <td width="363" height="21" align="left">tel: '.$tel.'</td>
  166. </tr>
  167. <tr>
  168. <td width="155" height="21" align="left"><b>Forma odpowiedzi:</b></td>
  169. <td width="363" height="21" align="left">'.$select.'</td>
  170. </tr>
  171. <tr>
  172. <td width="155" height="21" align="left"><b><font color="#000080">Temat:</font></b></td>
  173. <td width="363" height="21" align="left"><font color="#000080"><b>'.$subject.'</b></font></td>
  174. </tr>
  175. <tr>
  176. <td width="522" height="21" colspan="2" align="left">
  177. <p align="left">--------------------------------------------------------------</td>
  178. </tr>
  179. <tr>
  180. <td width="522" height="21" colspan="2" align="left"><i>'.$tresc.'</i></td>
  181. </tr>
  182. </table>
  183. </div>
  184.  
  185. </body>
  186. </html>
  187.  
  188. ';
  189.  
  190.  
  191. //naglowki:
  192.  
  193. $naglowki = "MIME-Version: 1.0rn";
  194. $naglowki .= "Content-type: text/html; charset=utf-8rn";
  195.  
  196.  
  197. //dodatkowy naglowek
  198.  
  199. $naglowki .= "From: tienspolska.com <adiscann@wp.pl>rn";
  200. //$naglowki .= "Cc: wiadomo rn";
  201. //$naglowki .= "Bcc: wiadomo rn";
  202.  
  203.  
  204. mail ($do,$subject,$wiadomosc,$naglowki);
  205.  
  206. //print_r($_POST);
  207.  
  208. };
  209.  
  210. ?>


Ten post edytował adiscan 16.04.2007, 18:59:41
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Statozor
post
Post #2





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 23.09.2006

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


Przypatrz się temu uważnie. Co masz w tej zmiennej i czy ją wyświetlasz ? (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Powinno działac
  1. <html>
  2. <head>
  3. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-2">
  4. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  5. <meta name="ProgId" content="FrontPage.Editor.Document">
  6. <title>Formularz Kontaktowy</title>
  7. </head>
  8.  
  9. <body>
  10.  
  11. <p align="center">
  12. <div align="right">
  13. <form action="Untitled.php" name="form" method="post">
  14.  <center>
  15. <table border="0" cellpadding="0" cellspacing="1" width="322" height="533" bgcolor="#EDFCE0" style="border: 0 double #008000">
  16. <tr>
  17. <td width="627" height="30" colspan="4" bordercolor="#00FFFF" bgcolor="#BCE184">
  18. <p align="center"><font color="#FFFFFF"><b>Formularz Kontaktowy</b></font> </td>
  19. </tr>
  20. <tr>
  21. <td width="193" height="40" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Imię i 
  22. Nazwisko:  </font> </td>
  23. <td width="759" colspan="3" height="40"> <input type="text" name="name" size="55" value="<?php echo $_POST['name']; ?>"></td>
  24. </tr>
  25. <tr>
  26. <td width="193" height="25" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Ulica:</font></td>
  27. <td width="418" colspan="3" height="25"> <input type="text" name="ulica" value="<?php echo $_POST['ulica']; ?>" size="55"></td>
  28. </tr>
  29. <tr>
  30. <td width="193" height="40" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Nr domu:</font></td>
  31. <td width="137" height="40"> <input type="text" name="numer" size="10" value="<?php echo $_POST['numer']; ?>"></td>
  32. <td width="198" height="40">
  33. <p align="center"><font face="Arial" size="2">Kod pocztowy:</font></td>
  34. </center>
  35. <td width="424" height="40">
  36. <p align="left"><input type="text" name="kod" size="14" value="<?php echo $_POST['kod']; ?>"></td>
  37. </tr>
  38. <center>
  39. <tr>
  40. <td width="193" height="26" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Miejscowość: </font> </td>
  41. <td width="759" colspan="3" height="26"> <input type="text" name="miejscowosc" value="<?php echo $_POST['miejscowosc']; ?>" size="55"></td>
  42. </tr>
  43. <tr>
  44. <td width="193" height="25" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Twoj Email:</font></td>
  45. <td width="759" colspan="3" height="25"> <input type="text" name="email" size="55" value="<?php echo $_POST['email']; ?>"></td>
  46. </tr>
  47. <tr>
  48. <td width="193" height="40" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Jak mamy Ci
  49. odpowiedzieć?</font></td>
  50. <td width="759" colspan="3" height="40"> <select size="1" name="select">
  51. <option selected>E-mail zwrotny</option>
  52. <option>Telefonicznie
  53. </option>
  54. </select>  <font size="2" face="Arial"> nr tel. </font><font size="1"> 
  55. </font><input type="text" name="tel" size="12"></td>
  56. </tr>
  57. <tr>
  58. <td width="193" height="40" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Temat
  59. wiadomoćci:  </font>
  60. </td>
  61. <td width="759" colspan="3" height="40"> <select size="1" name="subject">
  62. <option selected>Pytanie odnośnie produktów firmy Tiens</option>
  63. <option>Karta Klienta Firmy Tiens - informacje</option>
  64. <option>Zamówienie</option>
  65. <option>Reklamacje</option>
  66. <option>Inny</option>
  67.  
  68. </select></td>
  69. </tr>
  70. <tr>
  71. <td width="193" height="271" style="border-right-style: double" bordercolor="#BCE184" bordercolorlight="#EDFCE0" bordercolordark="#BCE184"><font size="2" face="Arial">Treść
  72. wiadomoćci:</font></td>
  73. <td width="759" colspan="3" height="271" style="border-top-style: double" bordercolor="#BCE184"><textarea rows="13" name="tresc" cols="50"><?php echo $_POST['tresc']; ?></textarea></td>
  74. </tr>
  75. <tr>
  76. <td width="902" height="27" colspan="4" align="center" bgcolor="#BCE184">
  77. <input type="submit" value=" Wyślij  " style="border-style: double; border-color: #008000" name='submit'></td>
  78. <input type="reset" value="reset">
  79. </tr>
  80. </table>
  81. </center>
  82. </div>
  83. <p align="left"> 
  84. <p align="left"> 
  85. <p align="left"><br>
  86. </p>
  87. </form>
  88.  
  89. </body>
  90.  
  91. </html>
  92.  
  93. <?php
  94.  
  95. function check_array($array) {
  96. foreach($array as $key => $value) {
  97.  if(empty($value)) {
  98. return FALSE;
  99.  }
  100. }
  101. return TRUE;
  102. }
  103. $name = $_POST['name'];
  104. $ulica = $_POST['ulica'];
  105. $numer = $_POST['numer'];
  106. $kod = $_POST['kod'];
  107. $miejscowosc = $_POST['miejscowosc'];
  108. $email = $_POST['email'];  //email tego kto ma pytanie
  109. $select = $_POST['select'];
  110. $tel = $_POST['tel'];
  111. $tresc = $_POST['tresc'];
  112.  
  113. /////////////////////////////////////////////////////////////
  114.  
  115.  
  116. if (isset($_POST['submit'])) {
  117. if(!check_array($_POST))
  118. {
  119.  echo $error;
  120.  
  121. }
  122. else
  123.  
  124. {
  125. //adresaci
  126. $do = " wiadomo ".",";
  127. $do .= " wiadomo ";
  128.  
  129. // temat maila
  130. $subject = $_POST['subject'];
  131.  
  132. // wiadomosc
  133.  
  134. $wiadomosc .= '
  135. <html>
  136. <head>
  137. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  138. <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
  139. <meta name="ProgId" content="FrontPage.Editor.Document">
  140. <title>Tytuł tej wiadomosci:</title>
  141. </head>
  142.  
  143. <body>
  144.  
  145.  
  146. <div align="left">
  147. <table border="0" cellpadding="0" cellspacing="1" width="528" height="158">
  148. <tr>
  149. <td width="155" height="20" align="left"><b>Imie i Nazwisko:</b></td>
  150. <td width="363" height="20" align="left">'.$name.'</td>
  151. </tr>
  152. <tr>
  153. <td width="155" height="21" align="left"><b>Adres:</b></td>
  154. <td align="left" width="359">'.$ulica.' '.$numer.'</td>
  155. </tr>
  156. <tr>
  157. <td width="155" height="21" align="left"></td>
  158. <td align="left" width="359">'.$kod.' '.$miejscowosc.'</td>
  159. </tr>
  160. <tr>
  161. <td width="155" height="19" align="left"><b>Kotnakt:</b></td>
  162. <td width="359" height="19" align="left">e-mail: '.$email.'</td>
  163. </tr>
  164. <tr>
  165. <td width="155" height="21" align="left"></td>
  166. <td width="363" height="21" align="left">tel: '.$tel.'</td>
  167. </tr>
  168. <tr>
  169. <td width="155" height="21" align="left"><b>Forma odpowiedzi:</b></td>
  170. <td width="363" height="21" align="left">'.$select.'</td>
  171. </tr>
  172. <tr>
  173. <td width="155" height="21" align="left"><b><font color="#000080">Temat:</font></b></td>
  174. <td width="363" height="21" align="left"><font color="#000080"><b>'.$subject.'</b></font></td>
  175. </tr>
  176. <tr>
  177. <td width="522" height="21" colspan="2" align="left">
  178. <p align="left">--------------------------------------------------------------</td>
  179. </tr>
  180. <tr>
  181. <td width="522" height="21" colspan="2" align="left"><i>'.$tresc.'</i></td>
  182. </tr>
  183. </table>
  184. </div>
  185.  
  186. </body>
  187. </html>
  188.  
  189. ';
  190.  
  191.  
  192. //naglowki:
  193.  
  194. $naglowki = "MIME-Version: 1.0rn";
  195. $naglowki .= "Content-type: text/html; charset=utf-8rn";
  196.  
  197.  
  198. //dodatkowy naglowek
  199.  
  200. $naglowki .= "From: tienspolska.com <adiscann@wp.pl>rn";
  201. //$naglowki .= "Cc: wiadomo rn";
  202. //$naglowki .= "Bcc: wiadomo rn";
  203.  
  204.  
  205. mail ($do,$subject,$wiadomosc,$naglowki);
  206.  
  207.  
  208.  
  209. }
  210. }
  211. print_r($_POST);
  212. ?>


Ten post edytował Statozor 17.04.2007, 21:21:50
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 9.10.2025 - 02:45