Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][JavaScript] Konflikt walidacji java script z formularzem
Forum PHP.pl > Forum > Przedszkole
bey
Pisałem na ten temat wcześniej, ale teraz myślę, że zdiagnozowałem przyczynę, chociaż nadal nie wiem co zrobić żeby wszystko działało jak powinno. Dane z formularza są wysyłane tak jak powinny jeśli usunę jego współprace z javascript, tak że zostanie praktycznie wyłącznie php, ale nie do końca mnie to ratuje, jeśli ktokolwiek orientuję się w tym temacie to proszę o pomoc, sprawa zaczyna być gardłowa a pomysły mi się wyczerpują smile.gif Wklejam kompletny kod php z javascript.

Kod formularza:
  1. <script type="text/javascript">
  2. $(document).ready(function(){
  3.  
  4. $("#recordClientPhone").mask("999-999-999");
  5. $("#recordClientPhoneAlt").mask("999-999-999");
  6. $("#recordClientZip").mask("99-999");
  7. $("#recordPropertyZip").mask("99-999");
  8. $("#recordPurchaseZip").mask("99-999");
  9.  
  10. // add * to required field labels
  11. $('label.required').append(' <strong>*</strong> ');
  12.  
  13. // accordion functions
  14. var accordion = $("#stepForm").accordion();
  15. var current = 0;
  16.  
  17. $.validator.addMethod("pageRequired", function(value, element) {
  18. var $element = $(element)
  19. function match(index) {
  20. return current == index && $(element).parents("#sf" + (index + 1)).length;
  21. }
  22. if (match(0) || match(1)) {
  23. return !this.optional(element);
  24. }
  25. return "dependency-mismatch";
  26. }, $.validator.messages.required)
  27.  
  28. var v = $("#cmaForm").validate({
  29. errorClass: "warning",
  30. onkeyup: false,
  31. onblur: false,
  32. submitHandler: function() {
  33. alert("Wiadomość wysłana, dziękuje!");
  34. }
  35. });
  36.  
  37. // back buttons do not need to run validation
  38. $("#sf2 .prevbutton").click(function(){
  39. accordion.accordion("activate", 0);
  40. current = 0;
  41. });
  42. $(".open1").click(function() {
  43. if (v.form()) {
  44. accordion.accordion("activate", 1);
  45. current = 1;
  46. }
  47. });
  48. $(".open0").click(function() {
  49. if (v.form()) {
  50. accordion.accordion("activate", 0);
  51. current = 0;
  52. }
  53. });
  54.  
  55. });
  56. </script>
  57. <link rel="stylesheet" type="text/css" media="screen" href="style.css" />
  58. </head>
  59.  
  60.  
  61. <body>
  62.  
  63. <div id="wrap">
  64. <div id="main">
  65.  
  66. <form name="cmaForm" id="cmaForm" method="post" action="check.php">
  67. <input type="hidden" name="recordRequestPrimaryServiceID" id="recordRequestPrimaryServiceID" value="100" />
  68. <input type="hidden" name="recordClientServices" id="recordClientServices" value="1,2" />
  69. <ul id="stepForm" class="ui-accordion-container">
  70. <li id="sf1"><a href='#' class="ui-accordion-link"> </a>
  71. <div>
  72. <fieldset><legend> Część 1 z 2 </legend>
  73. <div class="requiredNotice">*Pola obowiązkowe</div>
  74. <h3 class="stepHeader">Pytnia na temat 1</h3>
  75. <label for="recordClientNameFirst" class="input required">Imię</label>
  76. <input name="recordClientNameFirst" id="recordClientNameFirst" class="inputclass pageRequired" title="Proszę o wpisanie swojego imienia " maxlength="254" size="20" /> <br />
  77. <label for="recordClientNameLast" class="input required">Nazwisko</label> <input name="recordClientNameLast" id="recordClientNameLast" class="inputclass pageRequired" maxlength="254" title="Proszę o wpisanie swojego nazwiska" /> <br />
  78. <label for="recordClientAddress1" class="input required">Adres</label> <input name="recordClientAddress1" id="recordClientAddress1" class="inputclass pageRequired" maxlength="254" title="Proszę o wpisanie swojego adresu" /> <br />
  79. <label for="recordClientAddress2" class="input"></label> <input name="recordClientAddress2" id="recordClientAddress2" class="inputclass" maxlength="254" /> <br />
  80. <label for="recordClientCity" class="input required">Miasto</label> <input name="recordClientCity" id="recordClientCity" class="inputclass pageRequired" maxlength="254" title="Proszę o wpisanie miasta" /> <br />
  81. <div class="formspacer"></div>
  82. <div class="buttonWrapper"><input name="formNext1" type="button" class="open1 nextbutton" value="Next" alt="Next" title="Następny" /></div>
  83. </fieldset>
  84. </div>
  85. </li>
  86. <li id="sf2">
  87. <a href='#' class="ui-accordion-link">
  88. </a>
  89. <div>
  90. <fieldset><legend> Część 2 of 2 </legend>
  91. <div class="requiredNotice">*Pola obowiązkowe</div>
  92. <h3 class="stepHeader">Pytania na temat 2</h3>
  93. <label for="recordPurchaseMetRealtor" class="input required">Płeć</label> Mężczyzna: <input name="recordPurchaseMetRealtor" type="radio" checked="checked" class="inputclass" value="0" /> Kobieta: <input name="recordPurchaseMetRealtor" type="radio" class="inputclass pageRequired" value="1" title="Proszę wybrać jedną z opcji" /><br>
  94. <label for="recordClientZip" class="input required">Kod pocztowy:</label> <input name="recordClientZip" id="recordClientZip" class="inputclass pageRequired" maxlength="12" title="Proszę wpisać kod pocztowy" /> <br />
  95. <label for="recordClientPhone" class="input required">Numer telefonu</label> <input name="recordClientPhone" id="recordClientPhone" class="inputclass pageRequired" maxlength="254" title="Proszę o wpisanie numeru telefonu" /> <br />
  96. <label for="recordClientEmail" class="input required">Adres e-mail</label> <input name="recordClientEmail" id="recordClientEmail" class="inputclass pageRequired email" maxlength="254" title="Proszę o wpisanie adresu e-mail" /> <br />
  97. <div class="buttonWrapper"><input name="formBack1" type="button" class="open1 prevbutton" value="Back" alt="Back" title="Powrót" />
  98. <input name="submit" type="submit" id="submit" value="Submit" class="submitbutton" alt="Submit" title="Wyślji"></div> </fieldset>
  99. </div>
  100. </li>
  101. </ul>
  102. </form>
  103.  
  104. </div>
  105. </div>
  106.  
  107. </body>
  108. </html>



Kod check.php:
  1. <?php
  2. $recordClientNameFirst = $_POST['recordClientNameFirst'];
  3. $recordClientNameLast = $_POST['recordClientNameLast'];
  4. $recordClientAddress1 = $_POST['recordClientAddress1'];
  5. $recordClientAddress2 = $_POST['recordClientAddress2'];
  6. $recordClientCity = $_POST['recordClientCity'];
  7. $recordPurchaseMetRealtor = $_POST['recordPurchaseMetRealtor'];
  8. $recordClientZip = $_POST['recordClientZip'];
  9. $recordClientPhone = $_POST['recordClientPhone'];
  10. $recordClientEmail = $_POST['recordClientEmail'];
  11.  
  12. $adresdo = "wojtek@pl";
  13. $temat = "formularz"
  14. $zawartosc = "Imię: ".$ecordClientNameFirst."\n"
  15. ."Nazwisko: ".$recordClientNameLast."\n"
  16. ."Adres1: ".$recordClientAddress1."\n"
  17. ."Adres2: ".$recordClientAddress2."\n"
  18. ."Miasto: ".$recordClientCity."\n"
  19. ."Płeć: ".$recordPurchaseMetRealtor."\n"
  20. ."Kod pocztowy: ".$recordClientZip."\n"
  21. ."Telefon: ".$recordClientPhone."\n"
  22. ."Adres email: ".$recordClientEmail."\n";
  23.  
  24. $adresod = "www.costam.pl";
  25.  
  26. mail($adresdo, $temat, $zawartosc, $adresod);
  27. ?>
  28. <html>
  29. <head>
  30. <title>komentarz przyjęty</title>
  31. </head>
  32. <body>
  33. <h1>Komentarz przyjęty</h1>
  34. </body>
  35. </html>
nospor
Pytasz o to już tu:
http://forum.php.pl/index.php?showtopic=15...mp;#entry757528
skoro doszła nowa opcja, to rozwin tamten temat a nie zakładasz drugi identyczny.
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.