Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Problem z wyświetlaniem błędów formularza
Fsh
post
Post #1





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 6.05.2007

Ostrzeżenie: (40%)
XX---


Witam wszystkich serdecznie,

Chciałbym żeby w moim formularzu były wyświetlane błędy w sytuacji jeśli użytkownik nie wpisze np. e-maila. Próbowałem już wielu sposób, ale żaden nie działa i jestem w kropce. Proszę o pomoc.

  1. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
  2. <div class="field"><label for="email">Email:</label><input id="email" name="email" type="text" class="area"/></div>
  3. <div class="field"><label for="name">Imię i Nazwisko:</label><input id="name" name="name" type="text" class="area"/></div>
  4. <div class="field"><label for="name">Przedmiot:</label><input id="name" name="przedmiot" type="text" class="area"/></div>
  5. <div class="field">
  6. <label for="school">Wybierz szkołę:</label>
  7. <select id="school" name="school" class="area2"/>
  8. <option value="podstawowa">Podstawowa</option>
  9. <option value="gimnazjum">Gimnazjum</option>
  10. <option value="srednia">Średnia</option>
  11. <option value="wyzsza">Wyższa</option>
  12. </select>
  13. </div>
  14. <div class="field"><label for="message">Treść:</label><textarea cols="41" rows="5" name="message"></textarea></div>
  15. <div class="field"><label for="tele">Załącznik:</label><input id="tele" name="filename" type="file" /></div>
  16. <div class="field">
  17. <label for="verif_box">Przepisz kod:</label>
  18. <div class="captcha_img"><img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" />
  19. </div>
  20. <?php if(isset($_GET['wrong_code'])){?>
  21. <div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;">Wrong verification code</div><br />
  22. <?php ;}?><input name="verif_box" type="text" id="verif_box" class="captcha_field"/></div>
  23. <input id="sendme" type="submit" value="" />
  24. </form>


  1. <?php
  2. if ($_SERVER['REQUEST_METHOD']=="POST"){
  3. $verif_box = $_REQUEST["verif_box"];
  4. // Set the "To" email address
  5. $to="#";
  6.  
  7. //Subject of the mail
  8. $subject="Zadanie domowe";
  9.  
  10. // Get the sender's name and email address plug them a variable to be used later
  11. $from = stripslashes($_POST['name'])."<".stripslashes($_POST['email'])."<".stripslashes($_POST['przedmiot'])."<".stripslashes($_POST['school']).">";
  12.  
  13. // Check for empty fields
  14. if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']))
  15. {
  16. $errors .= "\n Error: Wszystkie pola są wymagane";
  17. }
  18.  
  19. // Get all the values from input
  20. $name = $_POST['name'];
  21. $przedmiot = $_POST['przedmiot'];
  22. $school = $_POST['school'];
  23. $email_address = $_POST['email'];
  24. $message = $_POST['message'];
  25.  
  26. // Check the email address
  27. if (!eregi( "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email_address))
  28. {
  29. $errors .= "\n Error: Zły adres e-mail!";
  30. }
  31.  
  32. // Now Generate a random string to be used as the boundary marker
  33. $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
  34.  
  35. // Now Store the file information to a variables for easier access
  36. $tmp_name = $_FILES['filename']['tmp_name'];
  37. $type = $_FILES['filename']['type'];
  38. $file_name = $_FILES['filename']['name'];
  39. $size = $_FILES['filename']['size'];
  40.  
  41. // Now here we setting up the message of the mail
  42. $message = "\n\n Imię i Nazwisko: $name \n\n Przedmiot: $przedmiot \n\n Szkoła: $school \n\n E-Mail: $email_address \n\nWiadomość: \n\n $message \n\nPlik: $file_name";
  43.  
  44. // Check if the upload succeded, the file will exist
  45. if (file_exists($tmp_name)){
  46.  
  47. // Check to make sure that it is an uploaded file and not a system file
  48. if(is_uploaded_file($tmp_name)){
  49.  
  50. // Now Open the file for a binary read
  51. $file = fopen($tmp_name,'rb');
  52.  
  53. // Now read the file content into a variable
  54. $data = fread($file,filesize($tmp_name));
  55.  
  56. // close the file
  57. fclose($file);
  58.  
  59. // Now we need to encode it and split it into acceptable length lines
  60. $data = chunk_split(base64_encode($data));
  61. }
  62.  
  63. // Now we'll build the message headers
  64. $headers = "From: $from\r\n" .
  65. "MIME-Version: 1.0\r\n" .
  66. "Content-Type: multipart/mixed;\r\n" .
  67. " boundary=\"{$mime_boundary}\"";
  68.  
  69. // Next, we'll build the message body note that we insert two dashes in front of the MIME boundary when we use it
  70. $message = "This is a multi-part message in MIME format.\n\n" .
  71. "--{$mime_boundary}\n" .
  72. "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
  73. "Content-Transfer-Encoding: 7bit\n\n" .
  74. $message . "\n\n";
  75.  
  76. // Now we'll insert a boundary to indicate we're starting the attachment we have to specify the content type, file name, and disposition as an attachment, then add the file content and set another boundary to indicate that the end of the file has been reached
  77. $message .= "--{$mime_boundary}\n" .
  78. "Content-Type: {$type};\n" .
  79. " name=\"{$file_name}\"\n" .
  80. //"Content-Disposition: attachment;\n" .
  81. //" filename=\"{$fileatt_name}\"\n" .
  82. "Content-Transfer-Encoding: base64\n\n" .
  83. $data . "\n\n" .
  84. "--{$mime_boundary}--\n";
  85.  
  86. // Thats all.. Now we need to send this mail... :)
  87.  
  88.  
  89. if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
  90. (@mail($to, $subject, $message, $headers))
  91. ?>
  92. <div><center>Zgłoszenie zostało wysłane!</center></div>
  93. <?php
  94. }else
  95. {
  96. ?>
  97. <div><center>
  98. Wykryto błędy, spróbuj jeszcze raz.</center></div>
  99. <?php
  100. }
  101. }
  102. }
  103. ?>
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: 23.12.2025 - 17:59