Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]skrypt formularza- gdzie błąd?
Forum PHP.pl > Forum > Przedszkole
jimy
Jak w temacie. Modyfikuje pewny skrypt formularza kontaktowego. Przy ostatniej modyfikacji (dodaniu pola osoba kontaktowa) nie chce mi wysyłać, nie wiem czemu, postępowałem identycznie jak przy dodawaniu adres firmy. Proszę o sprawdzenie skryptu.

  1. <style type="text/css">
  2.  
  3.  
  4. #contactarea {
  5. color:white;
  6. width:250px;
  7. margin:0px auto;
  8. text-align:left;
  9. padding:15px;
  10. border:1px solid purple;
  11. background-color:#313131;
  12. font-weight: bold;
  13. font-family: Verdana, Arial;
  14. font-size: 10px;
  15. }
  16.  
  17. #inputbox {
  18. color:white;
  19. background:#313131;
  20. border: 1px solid purple;
  21. width: 210px;
  22. padding: 2px;
  23. font-weight: bold;
  24. font-family: Verdana, Arial;
  25. font-size: 10px;
  26. }
  27.  
  28. #inputlabel {
  29. font-weight: bold;
  30. font-family: Verdana, Arial;
  31. font-size: 10px;
  32.  
  33. }
  34.  
  35. #textarea {
  36. color:white;
  37. background:#313131;
  38. border: 1px solid purple;
  39. padding: 2px;
  40. font-weight: bold;
  41. font-family: Verdana, Arial;
  42. font-size: 10px;
  43. width:240px;
  44. }
  45.  
  46. #submitbutton {
  47. border: 1px solid #000;
  48. background-color: #eee;
  49.  
  50. }
  51.  
  52. <script language="javascript">
  53.  
  54. function createRequestObject() {
  55. var ro;
  56. var browser = navigator.appName;
  57. if(browser == "Microsoft Internet Explorer"){
  58. ro = new ActiveXObject("Microsoft.XMLHTTP");
  59. }else{
  60. ro = new XMLHttpRequest();
  61. }
  62. return ro;
  63. }
  64.  
  65. var http = createRequestObject();
  66.  
  67. function sendemail() {
  68. var msg = document.contactform.msg.value;
  69. var adres = document.contactform.adres.value;
  70. var osoba = document.contactform.osoba.value;
  71. var name = document.contactform.name.value;
  72. var email = document.contactform.email.value;
  73. var subject = document.contactform.subject.value;
  74. document.contactform.send.disabled=true;
  75. document.contactform.send.value='Sending....';
  76.  
  77. http.open('get', 'contact.php?msg='+msg+'&adres='+adres+'&osoba='+osoba+'&name='+name+'&subject='+subject+'&email='+email+'&action=send');
  78. http.onreadystatechange = handleResponse;
  79. http.send(null);
  80. }
  81.  
  82. function handleResponse() {
  83. if(http.readyState == 4){
  84. var response = http.responseText;
  85. var update = new Array();
  86.  
  87. if(response.indexOf('|' != -1)) {
  88. update = response.split('|');
  89. document.getElementById(update[0]).innerHTML = update[1];
  90.  
  91. }
  92. }
  93. }
  94. <div id="contactarea">
  95. <form name="contactform" id="contactform">
  96. <span id="inputlabel">Nazwa firmy:</span>   <input type="text" name="name" id="inputbox"><br /><br />
  97. <span id="inputlabel">Adres:</span><br /><textarea name="adres" rows="3" id="textarea"></textarea>
  98. <span id="inputlabel">Osoba kontaktowa:</span><br /><textarea name="osoba" rows="1" id="textarea"></textarea>
  99. <span id="inputlabel">E-mail:</span>    <input type="text" name="email" id="inputbox"><br /><br />
  100. <span id="inputlabel">Temat:</span> <input type="text" name="subject" id="inputbox"><br /><br />
  101. <span id="inputlabel">Treść:</span><br />
  102. <textarea name="msg" rows="10" id="textarea"></textarea>
  103. <br /><br />
  104. <input type="button" value="Wyślij" name="send" onclick="sendemail();" id="submitbutton">
  105.  
  106. </form>


i plik conntact.php


  1. <?php
  2. /*
  3.  
  4. Author: Andrew Walsh
  5. Date: 30/05/2006
  6. Codewalkers_Username: Andrew
  7.  
  8.  
  9. This script is a basic contact form which uses AJAX to pass the information to php, thus making the page appear to work without any refreshing or page loading time.
  10.  
  11. */
  12.  
  13. $to = "none@none.pl "; //This is the email address you want to send the email to
  14. $subject_prefix = ""; //Use this if you want to have a prefix before the subject
  15.  
  16. if(!isset($_GET['action']))
  17. {
  18. die("Strona nie może zostać wyświetlona"); //Just to stop people from visiting contact.php normally
  19. }
  20.  
  21. /* Now lets trim up the input before sending it */
  22.  
  23. $name = trim($_GET['name']); //The senders name
  24. $email = trim($_GET['email']); //The senders email address
  25. $subject = trim($_GET['subject']); //The senders subject
  26. $message = trim($_GET['msg']); //The senders message
  27. $adres = trim($_GET['adres']); //The senders message
  28. $osoba = trim($_GET['osoba']); //The senders message
  29.  
  30. mail($to,$subject,$message,$osoba,"Adres firmy: ".$adres,"From: ".$email.""); //a very simple send
  31.  
  32. echo 'contactarea|Dziekujemy '.$name.', Twój e-mail zostal wyslany.'; //now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.
  33. ?>
Darti
Przerób ten textarea na input type text (skoro i tak masz tam jeden wiersz)
jimy
nie pomogło, pyzatym i tak muszę dodać jeszcze 2 text area więc i tak i tak muszą być
hondek
Z tego co wiem to id dla znacznika HTML musi byc unikalne, wiec :
  1. <span id="inputlabel">Adres:</span><br /><textarea name="adres" rows="3" id="textarea"></textarea>
  2. <span id="inputlabel">Osoba kontaktowa:</span><br /><textarea name="osoba" rows="1" id="textarea"></textarea>

jest raczej bledne, ale nie wiem czy to zrodlo twoich problemow... smile.gif
slawny
Nie jestem pewien ale może przez to że w <form> brakuje method?
argon
Cytat
<form name="contactform" id="contactform">


Jak masz zamiar wysłać formularz nieokreślając metody?

  1. <form method = "POST" name = "contactform" id = "contactform">
jimy
niestety żadna z waszych podpowiedzi nie działa, określenie metody nic nie zmienia, wcześniej bez dodania pola osoba kontaktowa wysyłało poprawnie.
Wicepsik
  1. <form method = "POST" name = "contactform" id = "contactform">

I zamień wszystkie $_GET w skrypcie na $_POST
jimy
zmieniłem ale nic nie pomogło, pokazuje na wszelki wypadek jeszcze raz kod po zmianach

  1. <style type="text/css">
  2.  
  3.  
  4. #contactarea {
  5. color:white;
  6. width:250px;
  7. margin:0px auto;
  8. text-align:left;
  9. padding:15px;
  10. border:1px solid purple;
  11. background-color:#313131;
  12. font-weight: bold;
  13. font-family: Verdana, Arial;
  14. font-size: 10px;
  15. }
  16.  
  17. #inputbox {
  18. color:white;
  19. background:#313131;
  20. border: 1px solid purple;
  21. width: 210px;
  22. padding: 2px;
  23. font-weight: bold;
  24. font-family: Verdana, Arial;
  25. font-size: 10px;
  26. }
  27.  
  28. #inputlabel {
  29. font-weight: bold;
  30. font-family: Verdana, Arial;
  31. font-size: 10px;
  32.  
  33. }
  34.  
  35. #textarea {
  36. color:white;
  37. background:#313131;
  38. border: 1px solid purple;
  39. padding: 2px;
  40. font-weight: bold;
  41. font-family: Verdana, Arial;
  42. font-size: 10px;
  43. width:240px;
  44. }
  45.  
  46. #submitbutton {
  47. border: 1px solid #000;
  48. background-color: #eee;
  49.  
  50. }
  51.  
  52. <script language="javascript">
  53.  
  54. function createRequestObject() {
  55. var ro;
  56. var browser = navigator.appName;
  57. if(browser == "Microsoft Internet Explorer"){
  58. ro = new ActiveXObject("Microsoft.XMLHTTP");
  59. }else{
  60. ro = new XMLHttpRequest();
  61. }
  62. return ro;
  63. }
  64.  
  65. var http = createRequestObject();
  66.  
  67. function sendemail() {
  68. var msg = document.contactform.msg.value;
  69. var adres = document.contactform.adres.value;
  70. var osoba = document.contactform.osoba.value;
  71. var name = document.contactform.name.value;
  72. var email = document.contactform.email.value;
  73. var subject = document.contactform.subject.value;
  74. document.contactform.send.disabled=true;
  75. document.contactform.send.value='Sending....';
  76.  
  77. http.open('get', 'contact.php?msg='+msg+'&adres='+adres+'&osoba='+osoba+'&name='+name+'&subject='+subject+'&email='+email+'&action=send');
  78. http.onreadystatechange = handleResponse;
  79. http.send(null);
  80. }
  81.  
  82. function handleResponse() {
  83. if(http.readyState == 4){
  84. var response = http.responseText;
  85. var update = new Array();
  86.  
  87. if(response.indexOf('|' != -1)) {
  88. update = response.split('|');
  89. document.getElementById(update[0]).innerHTML = update[1];
  90.  
  91. }
  92. }
  93. }
  94. <div id="contactarea">
  95. <form name="contactform" id="contactform">
  96. <form method = "POST" name = "contactform" id = "contactform">
  97. <span id="inputlabel">Nazwa firmy:</span> &nbsp;&nbsp;<input type="text" name="name" id="inputbox"><br /><br />
  98. <span id="inputlabel">Adres:</span><br /><textarea name="adres" rows="3" id="textarea"></textarea>
  99. <span id="inputlabel">Osoba kontaktowa:</span> &nbsp;&nbsp;<input type="text" name="osoba" id="inputbox"><br /><br />
  100. <span id="inputlabel">E-mail:</span> &nbsp;&nbsp;&nbsp;<input type="text" name="email" id="inputbox"><br /><br />
  101. <span id="inputlabel">Temat:</span> <input type="text" name="subject" id="inputbox"><br /><br />
  102. <span id="inputlabel">Treść:</span><br />
  103. <textarea name="msg" rows="10" id="textarea"></textarea>
  104. <br /><br />
  105. <input type="button" value="Wyślij" name="send" onclick="sendemail();" id="submitbutton">
  106.  
  107. </form>


  1. <?php
  2. /*
  3.  
  4. Author: Andrew Walsh
  5. Date: 30/05/2006
  6. Codewalkers_Username: Andrew
  7.  
  8.  
  9. This script is a basic contact form which uses AJAX to pass the information to php, thus making the page appear to work without any refreshing or page loading time.
  10.  
  11. */
  12.  
  13. $to = "none@home.pl "; //This is the email address you want to send the email to
  14. $subject_prefix = ""; //Use this if you want to have a prefix before the subject
  15.  
  16. if(!isset($_POST['action']))
  17. {
  18. die("Strona nie może zostać wyświetlona"); //Just to stop people from visiting contact.php normally
  19. }
  20.  
  21. /* Now lets trim up the input before sending it */
  22.  
  23. $name = trim($_POST['name']); //The senders name
  24. $email = trim($_POST['email']); //The senders email address
  25. $subject = trim($_POST['subject']); //The senders subject
  26. $message = trim($_POST['msg']); //The senders message
  27. $adres = trim($_POST['adres']); //The senders message
  28. $osoba = trim($_POST['osoba']); //The senders message
  29.  
  30. mail($to,$subject,$message,$osoba,"Adres firmy: ".$adres,"From: ".$email.""); //a very simple send
  31.  
  32. echo 'contactarea|Dziekujemy '.$name.', Twój e-mail zostal wyslany.'; //now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.
  33. ?>
Wicepsik
  1. <form name="contactform" id="contactform">
  2. <form method = "POST" name = "contactform" id = "contactform">

Czemu 2x ?

  1. <form method="POST" name="contactform" id="contactform">
jimy
faktycznie, ale nie wiem skąd takie uparcie przy metodzie skoro wcześniej gdy było mniej pól działało poprawnie bez niej
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.