Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] formularz kontaktowy
Forum PHP.pl > Forum > Przedszkole
Sebastian003
Witam mam takowy problem dodałem nowe pola do formularza ale nie wiem jak skonfigurować to zeby przysyłało mi także nowe pola dodane.

plik sendemail

  1. <?php
  2.  
  3. /************************
  4. * Variables you can change
  5. *************************/
  6.  
  7. $mailto = "www@nazwa.pl"; // Enter your mail addres here.
  8. $name = ucwords($_POST['name']);
  9. $subject = "Message from $name"; // Enter the subject here.
  10. $email = $_POST['email'];
  11. $message = $_POST['message'];
  12.  
  13. if(strlen($_POST['name']) < 1 ){
  14. echo 'email_error';
  15. }
  16.  
  17. else if(strlen($email) < 1 ) {
  18. echo 'email_error';
  19. }
  20.  
  21. else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $email)) {
  22. echo 'email_error';
  23. }
  24.  
  25. else if(strlen($message) < 1 ){
  26. echo 'email_error';
  27.  
  28. } else {
  29.  
  30. // NOW SEND THE ENQUIRY
  31.  
  32. $email_message="\n\n" .
  33. "Name: " .
  34. ucwords($name) .
  35. "\n" .
  36. "Email: " .
  37. $email .
  38. "\n" .
  39. "Comments: " .
  40. "\n" .
  41. $message .
  42. "\n" .
  43. "\n\n" ;
  44.  
  45. $email_message = trim(stripslashes($email_message));
  46. mail($mailto, $subject, $email_message, "From: \"$vname\" <".$email.">\nReply-To: \"".ucwords($name)."\" <".$email.">\nX-Mailer: PHP/" . phpversion() );
  47.  
  48. }
  49. ?>

JS
  1. $(document).ready(function() {
  2. $('#buttonsend').click( function() {
  3.  
  4. var name = $('#name').val();
  5. var subject = $('#subject').val();
  6. var email = $('#email').val();
  7. var message = $('#message').val();
  8.  
  9. $('.loading, .loading-side').fadeIn('fast');
  10.  
  11. if (name != "" && subject != "" && email != "" && message != "")
  12. {
  13.  
  14. $.ajax(
  15. {
  16. url: './sendemail.php',
  17. type: 'POST',
  18. data: "name=" + name + "&subject=" + subject + "&email=" + email + "&message=" + message,
  19. success: function(result)
  20. {
  21. $('.loading, .loading-side').fadeOut('fast');
  22. if(result == "email_error") {
  23. $('#email').css({"background":"#FFFCFC","border":"1px solid #ffb6b6"}).next('.require').text(' !');
  24. } else {
  25. $('#name, #subject, #email, #message').val("");
  26. $('<div class="success-contact"><img src="images/success.png" alt="" class="success-icon" />Your message has been sent successfully. Thank you! </div>').insertBefore('#contactFormArea');
  27. $('.success-contact').fadeOut(5000, function(){ $(this).remove(); });
  28. }
  29. }
  30. }
  31. );
  32. return false;
  33.  
  34. }
  35. else
  36. {
  37. $('.loading, .loading-side').fadeOut('fast');
  38. if( name == "") $('#name').css({"background":"#FFFCFC","background-image":"url(images/search-line-error.gif)","background-repeat":"repeat-x","background-position":"top"});
  39. if(subject == "") $('#subject').css({"background":"#FFFCFC","background-image":"url(images/search-line-error.gif)","background-repeat":"repeat-x","background-position":"top"});
  40. if(email == "" ) $('#email').css({"background":"#FFFCFC","background-image":"url(images/search-line-error.gif)","background-repeat":"repeat-x","background-position":"top"});
  41. if(message == "") $('#message').css({"background":"#FFFCFC","background-image":"url(images/search-line-error.gif)","background-repeat":"repeat-x","background-position":"top"});
  42. return false;
  43. }
  44. });
  45.  
  46. $('#name, #subject, #email,#message').focus(function(){
  47. $(this).css({"background":"#e6e6e6","background-image":"url(images/search-line.gif)","background-repeat":"repeat-x","background-position":"top","border":"none"});
  48. });
  49.  
  50. });


i html

  1. <!DOCTYPE html SYSTEM "http://www.indonez.com/xhtml1-iframe.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.  
  4.  
  5. <!-- ////////////////////////////////// -->
  6. <!-- // Javascript Files // -->
  7. <!-- ////////////////////////////////// -->
  8. <script type="text/javascript" src="jquery.min.js"></script>
  9. <script type="text/javascript" src="contact-form.js"></script>
  10.  
  11.  
  12. </head>
  13.  
  14.  
  15. <div id="contactFormArea">
  16. <!-- Contact Form Start //-->
  17. <form action="#" id="contactform">
  18. <div class="label-form-inline">
  19. <label>Imię i nazwisko :</label>
  20. <input type="text" name="name" class="textfield" id="name" value="" />
  21. </div>
  22. <div class="label-form-inline">
  23. <label>Email :</label>
  24. <input type="text" name="email" class="textfield" id="email" value="" />
  25. </div>
  26. <div class="label-form-inline-last">
  27. <label>Nazwa firmy :</label>
  28. <input type="text" name="firma" class="textfield" id="email" value="" />
  29. </div>
  30. <div class="label-form-inline">
  31. <label>Jak do nas trafiłeś?</label>
  32. <option>Wyszukiwarka Google</option>
  33. <option>cos</option>
  34. <option>cos2</option>
  35. <option>cos3</option>
  36. <option>cos4</option>
  37. </select>
  38. </div>
  39. <div class="label-form-inline">
  40. <label>Wybierz usługę :</label>
  41. </select>
  42. </div>
  43.  
  44. <div class="label-form-inline-last">
  45. <label>Kod promocyjny :</label>
  46. <input type="text" name="email" class="textfield" id="email" value="" />
  47.  
  48. </div>
  49. <div style="float:left;">
  50.  
  51. <label>Treść wiadomości :</label><br />
  52. <textarea name="message" id="message" class="textarea" cols="2" rows="7"></textarea>
  53.  
  54.  
  55. </div>
  56.  
  57.  
  58.  
  59. </form>
  60. <!-- Contact Form End //-->
  61. <input class="check" type="checkbox" value="1" name="acce">
  62. <span style="font-size:10px;">Wyrażam zgodę na otrzymywanie informacji handlowej drogą ektroniczną zgodnie z ustawą z dnia 26.08.2002r o świadczeniu</span>
  63.  
  64. <br />
  65. <input class="check" type="checkbox" value="1" name="ikno">
  66. <span style="font-size:10px;">Zapoznałem się i akceptuję politykę prywatności na stronie internetowej </span>
  67. <br /><br />
  68. <button type="submit" name="submit" id="buttonsend" class="input-submit">WYŚLIJ</button>
  69. <span class="loading" style="display: none;">Chwileczkę..</span>
  70. </div>
  71.  
  72. </div>
  73. <script type="text/javascript">$('#noscript').remove();</script>
  74. </body>
  75. </html>
Daiquiri
Musisz odebrać i przetworzyć zmienne, które wysyłasz w $email_message. Zasadniczo musisz dla nowych pól wykonać akcję analogiczną do np. $_POST['email'];
Sebastian003
Nie za bardzo rozumiem, Mógłby mi ktoś jakoś pokazać w prosty sposób jak to wykonać np dla jednego pola ?
Daiquiri
W formularzu masz pole <input type="text" name="email" class="textfield" id="email" value="" />, w skrypcie masz natomiast: $email = $_POST['email'];. Do zmiennej przechowującej treść ($email_message) dodajesz zmienną skróconą, czyli $email.

Z nowym polem postępujesz analogicznie. Możesz skrócić sobie zmienną (jak np. $zmienna = $_POST['zmienna']wink.gif i dodać ją do zmiennej $email_message, ponieważ to ona stanowi zasadniczą treść wysyłanego e-maila.
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.