Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Php Formularz
Forum PHP.pl > Forum > PHP
agusiapio
Moje pytanie brzmi czy możne ktoś mi nie wiem pomóc jak zrobić by było więcej tych pól do wypełniania i na czym to polega jak i bym chciała jeszcze ze 3 takie aby wrzucić załącznik na pocztę

  1. <?php
  2.  
  3. function print_form(){
  4. ?>
  5. <p><span class="required">*</span> Wymagane pola</p>
  6. <form method="post" action="<?php echo $_SERVER[?PHP_SELF?];?>" id="uploadform" enctype="multipart/form-data">
  7. <p><label for="namefrom">Imie <span class="required">*</span></label>
  8. <input name="namefrom" id="namefrom" type="text" class="field" value="<?= $_SESSION['myForm']['namefrom']; ?>" tabindex="1"/></p>
  9.  
  10. <p><label for="company">Firma</label>
  11. <input name="company" id="company" type="text" class="field" value="<?= $_SESSION['myForm']['company']; ?>" tabindex="2"/></p>
  12.  
  13. <p><label for="emailfrom">Adres email <span class="required">*</span></label>
  14. <input name="emailfrom" id="emailfrom" type="text" class="field" value="<?= $_SESSION['myForm']['emailfrom']; ?>" tabindex="3"/></p>
  15.  
  16. <p><label for="phone">Telefon kontaktowy</label>
  17. <input name="phone" id="phone" type="text" class="field" value="<?= $_SESSION['myForm']['phone']; ?>" tabindex="4"/></p>
  18.  
  19. <p><label for="subject">Temat <span class="required">*</span></label>
  20. <input name="subject" id="subject" type="text" class="field" value="<?= $_SESSION['myForm']['subject']; ?>" tabindex="5"/></p>
  21.  
  22. <p><label for="comments">Tresc <span class="required">*</span></label>
  23. <textarea name="comments" id="comments" rows="7" cols="10" class="field" tabindex="6"><?= $_SESSION['myForm']['comments']; ?></textarea></p>
  24.  
  25. <p><label for="attachment">Zalacz plik<br />(1 plik o maksymalnej wielkosci 8MB)</label>
  26. <input name="attachment" id="attachment" type="file" tabindex="7">
  27.  
  28. <p><input type="submit" name="submit" id="submit" value="Send Email!" tabindex="8"/></p>
  29. <p><input type="hidden" name="submitted" value="true" /></p>
  30. </form>
  31. <?php
  32. }
  33.  
  34. // enquiry form validation
  35.  
  36. function process_form() {
  37. // Read POST request params into global vars
  38. // FILL IN YOUR EMAIL
  39. $to = "your_mail@domena.pl";
  40. $subject = trim($_POST['subject']);
  41. $namefrom = trim($_POST['namefrom']);
  42. $company = trim($_POST['company']);
  43. $phone = trim($_POST['phone']);
  44. $emailfrom = trim($_POST['emailfrom']);
  45. $comments = trim($_POST['comments']);
  46.  
  47. // Allowed file types. add file extensions WITHOUT the dot.
  48. $allowtypes=array("jpg", "jpeg", "png", "gif", "bmp");
  49.  
  50. // Require a file to be attached: false = Do not allow attachments true = allow only 1 file to be attached
  51. $requirefile="true";
  52.  
  53. // Maximum file size for attachments in KB NOT Bytes for simplicity. MAKE SURE your php.ini can handel it,
  54. // post_max_size, upload_max_filesize, file_uploads, max_execution_time!
  55. // 2048kb = 2MB, 1024kb = 1MB, 512kb = 1/2MB etc..
  56. $max_file_size="8192";
  57.  
  58. // Thank you message
  59. $thanksmessage="Twoja wiadomosc zostala wyslana.<br />Dziekujemy.";
  60.  
  61. $errors = array(); //Initialize error array
  62.  
  63. //checks for a name
  64. if (empty($_POST['namefrom']) ) {
  65. $errors[]='Prosze podac imie.';
  66. }
  67.  
  68. //checks for an email
  69. if (empty($_POST['emailfrom']) ) {
  70. $errors[]='Prosze podac adres email.';
  71. } else {
  72.  
  73. if (!eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['emailfrom'])))) {
  74. $errors[]='Prosze podac prawidlowy adres email.';
  75. } // if eregi
  76. } // if empty email
  77.  
  78. //checks for a subject
  79. if (empty($_POST['subject']) ) {
  80. $errors[]='Prosze podac temat';
  81. }
  82.  
  83. //checks for a message
  84. if (empty($_POST['comments']) ) {
  85. $errors[]='Prosze podac tresc wiadomosci.';
  86. }
  87.  
  88. // checks for required file
  89. if($requirefile=="true") {
  90. if($_FILES['attachment']['error']==4) {
  91. $errors[]='Prosze zalaczyc plik.';
  92. }
  93. }
  94.  
  95. //checks attachment file
  96. // checks that we have a file
  97. if((!empty($_FILES["attachment"])) && ($_FILES['attachment']['error'] == 0)) {
  98. // basename -- Returns filename component of path
  99. $filename = basename($_FILES['attachment']['name']);
  100. $ext = substr($filename, strrpos($filename, '.') + 1);
  101. $filesize=$_FILES['attachment']['size'];
  102. $max_bytes=$max_file_size*1024;
  103.  
  104. //Check if the file type uploaded is a valid file type.
  105. if (!in_array($ext, $allowtypes)) {
  106. $errors[]="Niedozwolone rozszerzenie: <strong>".$filename."</strong>";
  107.  
  108. // check the size of each file
  109. } elseif($filesize > $max_bytes) {
  110. $errors[]= "Twoj plik: <strong>".$filename."</strong> jest za duzy. Maksymalna wielkosc pliku to ".$max_file_size."KB.";
  111. }
  112.  
  113. } // if !empty FILES
  114.  
  115. if (empty($errors)) { //If everything is OK
  116.  
  117. // send an email
  118. // Obtain file upload vars
  119. $fileatt = $_FILES['attachment']['tmp_name'];
  120. $fileatt_type = $_FILES['attachment']['type'];
  121. $fileatt_name = $_FILES['attachment']['name'];
  122.  
  123. // Headers
  124. $headers = "From: $emailfrom";
  125.  
  126. // create a boundary string. It must be unique
  127. $semi_rand = md5(time());
  128. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  129.  
  130. // Add the headers for a file attachment
  131. $headers .= "\nMIME-Version: 1.0\n" .
  132. "Content-Type: multipart/mixed;\n" .
  133. " boundary=\"{$mime_boundary}\"";
  134.  
  135. // Add a multipart boundary above the plain message
  136. $message ="This is a multi-part message in MIME format.\n\n";
  137. $message.="--{$mime_boundary}\n";
  138. $message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
  139. $message.="Content-Transfer-Encoding: 7bit\n\n";
  140. $message.="From: ".$namefrom."\n";
  141. $message.="Company: ".$company."\n";
  142. $message.="Phone: ".$phone."\n";
  143. $message.="Comments: ".$comments."\n\n";
  144.  
  145. if (is_uploaded_file($fileatt)) {
  146. // Read the file to be attached ('rb' = read binary)
  147. $file = fopen($fileatt,'rb');
  148. $data = fread($file,filesize($fileatt));
  149. fclose($file);
  150.  
  151. // Base64 encode the file data
  152. $data = chunk_split(base64_encode($data));
  153.  
  154. // Add file attachment to the message
  155. $message .= "--{$mime_boundary}\n" .
  156. "Content-Type: {$fileatt_type};\n" .
  157. " name=\"{$fileatt_name}\"\n" .
  158. //"Content-Disposition: attachment;\n" .
  159. //" filename=\"{$fileatt_name}\"\n" .
  160. "Content-Transfer-Encoding: base64\n\n" .
  161. $data . "\n\n" .
  162. "--{$mime_boundary}--\n";
  163. }
  164.  
  165.  
  166. // Send the completed message
  167.  
  168. $envs = array("HTTP_USER_AGENT", "REMOTE_ADDR", "REMOTE_HOST");
  169. foreach ($envs as $env)
  170. $message .= "$env: $_SERVER[$env]\n";
  171.  
  172. if(!mail($to,$subject,$message,$headers)) {
  173. exit("Wystapil blad, wiadomosc nie zostala wyslana. Prosimy o zgloszenie tego administratorowi strony.\n");
  174. } else {
  175. echo '<div id="formfeedback"><h3>Dziekujemy!</h3><p>'. $thanksmessage .'</p></div>';
  176. unset($_SESSION['myForm']);
  177. print_form();
  178.  
  179. } // end of if !mail
  180.  
  181. } else { //report the errors
  182. echo '<div id="formfeedback"><h3>Blad!</h3><p>Nastepujace bledy wystapily:<br />';
  183. foreach ($errors as $msg) { //prints each error
  184. echo " - $msg<br />\n";
  185. } // end of foreach
  186. echo '</p><p>Prosze sprobowac ponownie.</p></div>';
  187. print_form();
  188. } //end of if(empty($errors))
  189.  
  190. } // end of process_form()
  191. ?>foreach ( as $key => $value)
  192. {
  193.  
  194. }
  195.  
caro1122
witam
moge pomóc, jak chodzi Ci o formularz php/html, mam program do pisania formularzy i można tam wszystko zrobić, załączniki, pola tekstowe, pola wielokrotnego wyboru itp... a co najważniejsze chodzi taki formularz.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.