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.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<div class="field"><label for="email">Email:
</label><input id="email" name="email" type="text" class="area"/></div> <div class="field"><label for="name">Imię i Nazwisko:
</label><input id="name" name="name" type="text" class="area"/></div> <div class="field"><label for="name">Przedmiot:
</label><input id="name" name="przedmiot" type="text" class="area"/></div> <select id="school" name="school" class="area2"/> <div class="field"><label for="tele">Załącznik:
</label><input id="tele" name="filename" type="file" /></div> <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" />
<?php if(isset($_GET['wrong_code'])){?>
<div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;">Wrong verification code
</div><br /> <?php ;}?><input name="verif_box" type="text" id="verif_box" class="captcha_field"/></div> <input id="sendme" type="submit" value="" />
<?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
// Check for empty fields
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) {
$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
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// 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
$file = fopen($tmp_name,'rb');
// 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... :)
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){ (@mail($to, $subject, $message, $headers)) ?>
<div><center>Zgłoszenie zostało wysłane!</center></div>
<?php
}else
{
?>
<div><center>
Wykryto błędy, spróbuj jeszcze raz.</center></div>
<?php
}
}
}
?>