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
adiscan
post
Post #2





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

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


Zrobiłem cos takiego żeby sprawdzał oczy pole NAME jest uzupelnione i ... nie działa (IMG:http://forum.php.pl/style_emoticons/default/exclamation.gif) !!!!

co ja żle robie !
pomożcie prosze bo już nie mam siły ...

plik test2.php



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


Ten post edytował adiscan 17.04.2007, 20:53:00
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: 27.12.2025 - 21:49