Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Formularz i problem z jego wysyłką
Forum PHP.pl > Forum > PHP
senior.pol
Witam,
Stworzyłem na bazie podanych tutoriali w sieci formularz, z którym mam problem, dokładniej z jego wysyłką.
Wstawiam wszystko co mam zrobione. Nie wiem jak użyć funkcji echo, dlatego mam wysyłkę do wszystkich foreach. Byłbym wdzięczny, także za pomoc w tym.

  1. <div id="steps">
  2. <form id="formElem" name="formElem" action="#" method="post">
  3. <fieldset class="step">
  4. <legend>Dane personalne</legend>
  5. <p>
  6. <label for="name">Imię i nazwisko</label>
  7. <input id="name" name="name" type="text" AUTOCOMPLETE=OFF />
  8. </p>
  9. <p>
  10. <label for="adres">Adres zamieszkania</label>
  11. <input id="adres" name="adres" type="text" AUTOCOMPLETE=OFF />
  12. </p>
  13. <p>
  14. <label for="telefon">Telefon</label>
  15. <input id="telefon" name="telefon" type="text" AUTOCOMPLETE=OFF />
  16. </p>
  17. <p>
  18. <label for="email">Email</label>
  19. <input id="email" name="email" type="text" AUTOCOMPLETE=OFF />
  20. </p>
  21. <fieldset class="step">
  22. <legend>Szczegóły dotyczące rezerwacji</legend>
  23. <p>
  24. <label for="typrejsu">Typ rejsu</label>
  25. <select id="typrejsu" name="typrejsu">
  26. <option>xxxxxxxxxxx</option>
  27. <option>xxxxxxxxxxx</option>
  28. </select>
  29. </p>
  30. <p>
  31. <label for="liczbamiejsc">Liczba rezerwowanych miejsc</label>
  32. <select id="liczbamiejsc" name="liczbamiejsc">
  33. </select>
  34. </p>
  35. <p>
  36. <label for="ubezpieczenie">Dodatkowe ubezpieczenie</label>
  37. <select id="ubezpieczenie" name="ubezpieczenie">
  38. <option>Tak</option>
  39. <option>Nie</option>
  40. </select>
  41. </p>
  42. <fieldset class="step">
  43. <legend>Szczegóły płatności</legend>
  44. <p>
  45. <label for="platnosc">Sposób płatności</label>
  46. <select id="platnosc" name="platnosc">
  47. <option>Gotówka</option>
  48. <option>Przelew</option>
  49. </select>
  50. </p>
  51. <p>
  52. <label for="waluta">Waluta</label>
  53. <select id="waluta" name="waluta" AUTOCOMPLETE=OFF>
  54. <option>PLN</option>
  55. <option>EU</option>
  56. </select>
  57. </p>
  58. <p>
  59. <label for="platnik">Imię i nazwisko Płatnika</label>
  60. <input id="platnik" name="platnik" AUTOCOMPLETE=OFF />
  61. </p>
  62. <p>
  63. <label for="pesel">PESEL Płatnika</label>
  64. <input id="pesel" name="pesel" AUTOCOMPLETE=OFF />
  65. </p>
  66. <fieldset class="step">
  67. <legend>Szczegóły wpłaty zaliczki</legend>
  68. <p>
  69. xxxxxxxxxx
  70. </p>
  71. <p>
  72. <label for="zaliczka">Potwierdzam wpłatę zaliczki</label>
  73. <select id="zaliczka" name="zaliczka">
  74. <option>Tak</option>
  75. <option>Nie</option>
  76. </select>
  77. </p>
  78. <fieldset class="step">
  79. <legend>Potwierdzenie uczestnictwa w rejsie</legend>
  80. <p>
  81. xxxxxxxxx
  82. </p>
  83. <input type="hidden" value="xyz@xyz.pl" name="to" id="to" />
  84. <input type="hidden" value="Rezerwacja" name="subject" id="subject" />
  85. <input type="hidden" value="rezerwacja.php" />
  86. <p class="submit">
  87. <button id="registerButton" type="button" name="submit" id="submit">Rezerwuj</button>
  88. </p>
  89. </form>


  1. <?php
  2.  
  3. $subject = $_POST['subject'];
  4. $to = explode(',', $_POST['to'] );
  5. $name = explode(',', $_POST['name'] );
  6. $adres = explode(',', $_POST['adres'] );
  7. $telefon = explode(',', $_POST['telefon'] );
  8. $typrejsu = explode(',', $_POST['typrejsu'] );
  9. $liczbamiejsc = explode(',', $_POST['liczbamiejsc'] );
  10. $ubezpieczenie = explode(',', $_POST['ubezpieczenie'] );
  11. $platnosc = explode(',', $_POST['platnosc'] );
  12. $waluta = explode(',', $_POST['waluta'] );
  13. $platnik = explode(',', $_POST['platnik'] );
  14. $pesel = explode(',', $_POST['pesel'] );
  15. $zaliczka = explode(',', $_POST['zaliczka'] );
  16. $from = $_POST['email'];
  17.  
  18. $msg = "<b>Imię i nazwisko:</b> " .$_POST['name'] ."<br>\n";
  19. $msg .= "<br>\n";
  20. $msg .= "<b>Adres email:</b> " .$_POST['email'] ."<br>\n";
  21. $msg .= "<b>Typ rejsu:</b> " .$_POST['typrejsu'] ."<br>\n";
  22. $msg .= "<b>Dane płatnika:</b> " .$_POST['platnik'] ."<br>\n";
  23. $msg .= "<b>Potwierdzenie wpłaty zaliczki:</b> " .$_POST['zaliczka'] ."<br>\n";
  24. $msg .= "<b>Waluta:</b> " .$_POST['waluta'] ."<br>\n";
  25.  
  26. $headers = "MIME-Version: 1.0\r\n";
  27. $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  28. $headers .= "From: <".$from. ">" ;
  29.  
  30.  
  31. foreach($to as $mail){
  32. mail($mail, $subject, $msg, $headers);
  33. }
  34.  
  35. ?>


Demo można zobaczyć tutaj: Link

Z góry dziękuję za pomoc i życzę Szczęśliwego Nowego Roku czarodziej.gif

Wrzucam jeszcze JS , bo wiadomość była za długa.

  1.  
  2. $(FUNCTION() {
  3.  
  4. var fieldsetCount = $('#formElem').children().length;
  5. var current = 1;
  6. var stepsWidth = 0;
  7. var widths = new Array();
  8. $('#steps .step').each(FUNCTION(i){
  9. var $step = $(this);
  10. widths[i] = stepsWidth;
  11. stepsWidth += $step.width();
  12. });
  13. $('#steps').width(stepsWidth);
  14. $('#formElem').children(':first').find(':input:first').focus();
  15. $('#navigation').SHOW();
  16. $('#navigation a').bind('click',FUNCTION(e){
  17. var $this = $(this);
  18. var prev = current;
  19. $this.closest('ul').find('li').removeClass('selected');
  20. $this.parent().addClass('selected');
  21.  
  22. current = $this.parent().INDEX() + 1;
  23.  
  24. $('#steps').stop().animate({
  25. marginLeft: '-' + widths[current-1] + 'px'
  26. },500,FUNCTION(){
  27. IF(current == fieldsetCount)
  28. validateSteps();
  29. else
  30. validateStep(prev);
  31. $('#formElem').children(':nth-child('+ parseInt(current) +')').find(':input:first').focus();
  32. });
  33. e.preventDefault();
  34. });
  35.  
  36. $('#formElem > fieldset').each(FUNCTION(){
  37. var $fieldset = $(this);
  38. $fieldset.children(':last').find(':input').keydown(FUNCTION(e){
  39. IF (e.which == 9){
  40. $('#navigation li:nth-child(' + (parseInt(current)+1) + ') a').click();
  41. $(this).blur();
  42. e.preventDefault();
  43. }
  44. });
  45. });
  46.  
  47. FUNCTION validateSteps(){
  48. var FormErrors = false;
  49. FOR(var i = 1; i < fieldsetCount; ++i){
  50. var error = validateStep(i);
  51. IF(error == -1)
  52. FormErrors = true;
  53. }
  54. $('#formElem').DATA('errors',FormErrors);
  55. }
  56.  
  57. FUNCTION validateStep(step){
  58. IF(step == fieldsetCount) RETURN;
  59.  
  60. var error = 1;
  61. var hasError = false;
  62. $('#formElem').children(':nth-child('+ parseInt(step) +')').find(':input:not(button)').each(FUNCTION(){
  63. var $this = $(this);
  64. var valueLength = jQuery.trim($this.val()).length;
  65.  
  66. IF(valueLength == ''){
  67. hasError = true;
  68. $this.css('background-color','#FFEDEF');
  69. }
  70. else
  71. $this.css('background-color','#FFFFFF');
  72. });
  73. var $link = $('#navigation li:nth-child(' + parseInt(step) + ') a');
  74. $link.parent().find('.error,.checked').remove();
  75.  
  76. var valclass = 'checked';
  77. IF(hasError){
  78. error = -1;
  79. valclass = 'error';
  80. }
  81. $('<span class="'+valclass+'"></span>').insertAfter($link);
  82.  
  83. RETURN error;
  84. }
  85.  
  86. $('#registerButton').bind('click',FUNCTION(){
  87. IF($('#formElem').DATA('errors')){
  88. alert('Prosimy poprawić dane w formularzu !');
  89. RETURN false;
  90. }
  91. });
  92. });
  93.  
aras785
Zmień w formularzu:
  1. <button id="registerButton" type="button" name="submit" id="submit">Rezerwuj</button>

na
  1. <input type="submit" id="registerButton" name="submit">Rezerwuj</button>


  1. <?php
  2.  
  3. $subject = $_POST['subject'];
  4. $to = $_POST['tu'];
  5. $from = $_POST['email'];
  6.  
  7. $msg = "<b>Imię i nazwisko:</b> " .$_POST['name'] ."<br>\n";
  8. $msg .= "<br>\n";
  9. $msg .= "<b>Adres email:</b> " .$_POST['email'] ."<br>\n";
  10. $msg .= "<b>Typ rejsu:</b> " .$_POST['typrejsu'] ."<br>\n";
  11. $msg .= "<b>Dane płatnika:</b> " .$_POST['platnik'] ."<br>\n";
  12. $msg .= "<b>Potwierdzenie wpłaty zaliczki:</b> " .$_POST['zaliczka'] ."<br>\n";
  13. $msg .= "<b>Waluta:</b> " .$_POST['waluta'] ."<br>\n";
  14.  
  15. $headers = "MIME-Version: 1.0\r\n";
  16. $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  17. $headers .= "From: <".$from. ">" ;
  18.  
  19. mail($to, $subject, $msg, $headers);
  20.  
  21. ?>


Nie wiem czy to zadziała. Na szybko:)
senior.pol
Nie działa.
Może to chodzi o tą linijkę też ?
  1. <input type="hidden" value="rezerwacja.php" />
aras785
  1. <form id="formElem" name="formElem" action="#" method="post">


na

  1. <form id="formElem" name="formElem" action="rezerwacja.php" method="post">
senior.pol
Błąd

  1. Warning: mail() expects parameter 1 to be string, array given in /home/senior67/domains/sternicy.com.pl/public_html/rezerwacja.php on line 35


Ktoś ma pomysł na rozwiązanie mojego problemu ?
memory
  1. $to
jest tablicą a musi być stringiem



  1. $to = explode(',', $_POST['to'] );
  2.  
  3. foreach($to as $mail){
  4. mail($mail, $subject, $msg, $headers);
  5. }
senior.pol
  1. to$string


Coś takiego ?
memory
znajdz
  1. foreach($to as $mail){
  2. mail($mail, $subject, $msg, $headers);
  3. }

i zamień na

  1. mail('biuro@sternicy.com.pl', $subject, $msg, $headers);


senior.pol
Ok działa guitar.gif Dziękuję bardzo za pomoc.
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.