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.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> <div class="field"> <select id="school" name="school" class="area2"/> </select> </div> <div class="field"> </div> <?php if(isset($_GET['wrong_code'])){?> <input id="sendme" type="submit" value="" /> </form>
<?php if ($_SERVER['REQUEST_METHOD']=="POST"){ $verif_box = $_REQUEST["verif_box"]; // Set the "To" email address $to="#"; //Subject of the mail $subject="Zadanie domowe"; // Get the sender's name and email address plug them a variable to be used later $from = stripslashes($_POST['name'])."<".stripslashes($_POST['email'])."<".stripslashes($_POST['przedmiot'])."<".stripslashes($_POST['school']).">"; // Check for empty fields { $errors .= "\n Error: Wszystkie pola są wymagane"; } // Get all the values from input $name = $_POST['name']; $przedmiot = $_POST['przedmiot']; $school = $_POST['school']; $email_address = $_POST['email']; $message = $_POST['message']; // Check the email address if (!eregi( "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email_address)) { $errors .= "\n Error: Zły adres e-mail!"; } // Now Generate a random string to be used as the boundary marker // Now Store the file information to a variables for easier access $tmp_name = $_FILES['filename']['tmp_name']; $type = $_FILES['filename']['type']; $file_name = $_FILES['filename']['name']; $size = $_FILES['filename']['size']; // Now here we setting up the message of the mail $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"; // Check if the upload succeded, the file will exist // Check to make sure that it is an uploaded file and not a system file // Now Open the file for a binary read // Now read the file content into a variable // close the file // Now we need to encode it and split it into acceptable length lines } // Now we'll build the message headers $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; // Next, we'll build the message body note that we insert two dashes in front of the MIME boundary when we use it $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; // 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 $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$file_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; // Thats all.. Now we need to send this mail... :) ?> <div><center>Zgłoszenie zostało wysłane!</center></div> <?php }else { ?> <div><center> Wykryto błędy, spróbuj jeszcze raz.</center></div> <?php } } } ?>