Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][PHP] Formularz kontaktowy
Forum PHP.pl > Forum > Przedszkole
lukasz94
Witam, mam problem z formularzem kontaktowym, includuje plik "kontakt.php" do głównego pliku index.php (index.php?id=kontakt.php), problem jest w tym, że wszystkie pola formularza są nieaktywne. Gdzie robię błąd, czy przesyłanie formularza w ten sposób jest błędne?

Fragment includowanie w index.php
  1. <?php
  2. if($_GET['id']=="kontakt") {
  3. include("kontakt.php");
  4. }
  5. elseif ($_GET['id']=="uslugi"){
  6. include("uslugi.php");
  7. }
  8. else{
  9. include("main.php");
  10. }
  11.  
  12.  
  13. ?>


plik kontakt.php
  1.  
  2. <?php
  3.  
  4.  
  5. if(isset($_POST['email'])) {
  6.  
  7. // EDIT THE 2 LINES BELOW AS REQUIRED
  8. $email_to = "pastucha.lukasz@gmail.com";
  9. $email_subject = "Biuro rachunkowe \"Kaja\"";
  10.  
  11. function died($error)
  12. {
  13. // your error code can go here
  14. echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  15. echo "These errors appear below.<br /><br />";
  16. echo $error . "<br /><br />";
  17. echo "Please go back and fix these errors.<br /><br />";
  18. die();
  19. }
  20.  
  21. // validation expected data exists
  22. if (
  23. !isset($_POST['email']) ||
  24. !isset($_POST['comments'])
  25. ) {
  26. died('Proszę wypełnić wszystkie pola');
  27. }
  28.  
  29.  
  30. $email_from = $_POST['email']; // required
  31. $comments = $_POST['comments']; // required
  32.  
  33. $error_message = "";
  34. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  35. if (!preg_match($email_exp, $email_from)) {
  36. $error_message .= 'Niepoprawny e-mail<br />';
  37. }
  38.  
  39.  
  40. if (strlen($comments) < 2) {
  41. $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  42. }
  43. if (strlen($error_message) > 0) {
  44. died($error_message);
  45. }
  46.  
  47.  
  48. function clean_string($string)
  49. {
  50. $bad = array("content-type", "bcc:", "to:", "cc:", "href");
  51. return str_replace($bad, "", $string);
  52. }
  53.  
  54.  
  55. $email_message .= "Email: " . clean_string($email_from) . "\n";
  56.  
  57. $email_message .= " " . clean_string($comments) . "\n";
  58.  
  59.  
  60. // create email headers
  61. $headers = 'From: ' . $email_from . "\r\n" .
  62. 'Reply-To: ' . $email_from . "\r\n" .
  63. 'X-Mailer: PHP/' . phpversion();
  64. @mail($email_to, $email_subject, $email_message, $headers);
  65.  
  66. }
  67. ?>


  1. <div class="dane_kontaktowe">
  2. <div class="top_title">
  3. <span>Kontakt</span>
  4. </div>
  5. <p>
  6. Biuro rachunkowe "Kaja"<br>
  7. Nietkowice 89<br>
  8. 66-100 Sulechów
  9. <br><br>
  10. <span><img src="ico/phone_ico.png">797 40 65 69</span>
  11. <br>
  12. <span><img src="ico/e_mail_ico.png">wajlerkielka@wp.pl</span>
  13. </p>
  14. </div>
  15.  
  16. <div class="contact_form">
  17. <form name="contactform" method="post" action="kontakt.php">
  18. <div class="box" >
  19. <h1>Napisz do nas:</h1>
  20. <label for="email">
  21. <span>E-mail:</span>
  22. <input type="text" class="wpis" name="email" id="email" />
  23. <br />
  24. <div id="iemail" class="error"></div>
  25. </label>
  26. <label for="comments"><span>Wiadomość:</span>
  27. <textarea class="message" name="comments" id="message">
  28.  
  29. </textarea><br />
  30. <div id="imessage" class="error"></div>
  31. <input name="submit" type="submit" class="button" value="Wyślij" id="submit"/>
  32. </label>
  33. </div>
  34. </form>
  35. </div>
jacobson
To: index.php?id=kontakt.php powinno być tym: index.php?id=kontakt i w samym formularzu podaj całą ścieżkę tzn www.twojastrona.pl/index.php?id=kontakt, sprawdź wtedy czy którekolwiek pole Ci przechodzi
lukasz94
Głupi błąd w css, okazało się że formularz miał atrybut z-index poniżej diva głównego przez co ten blokował dostęp do elementów formularza, swoją drogą dzięki bo te info też były istotne. smile.gif
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.