Witam mam taki problem z formularzem kontaktowym
  1. <div id="kont"> <form name="vform" id="vform" method="get" action="mail.php" width="300px">
  2.  
  3.  
  4. <div id="imie">
  5. <label for="imie" class="block">Imię i Nazwisko:</label></div>
  6. <div id="imie1"><input class="required,alphanum" type="text" name="imie" id="imie" autocomplete="off" /></div>
  7. <div id="imie2"><img width="16" height="16" name="imie" src="img/blank.gif" alt=""></div>
  8.  
  9.  
  10. <div id="email"><label for="email" class="block">Email:</label></div>
  11. <div id="email1"><input type="text" name="email" id="email" class="email" autocomplete="off" /></div>
  12. <div id="email2"><img width="16" height="16" name="email" src="img/blank.gif" alt=""></div>
  13.  
  14. <div id="tel"> <label for="tel" class="block">Telefon:</label></div>
  15. <div id="tel1"><input class="required,number" type="text" name="tel" id="tel" autocomplete="off" /></div>
  16. <div id="tel2"><img width="16" height="16" name="tel" src="img/blank.gif" alt=""></div>
  17.  
  18. <div id="wiad"> <label for="about" class="block">Treść <br />wiadomości:</label></div>
  19. <div id="wiad1"><textarea id="about" class="required,alphanum" cols="33" rows="4" style="overflow:hidden;" autocomplete="off"></textarea></div>
  20. <div id="wiad2"><img width="16" height="16" name="about" src="img/blank.gif" alt=""></div>
  21.  
  22.  
  23.  
  24. <div id="wyslij"> <input type="submit" name="submit" disabled="disabled" id="submit" value="wyślij" ></div>

  1. // Load the getForm function while page is loading
  2. window.onload = getForm;
  3.  
  4. // Set this to your validation PHP script, default is "validate.php?value="
  5. var vUrl = "http://localhost/cmsmade/validate.php?value=";
  6.  
  7. // Set this to your form's id
  8. var formid = "vform";
  9.  
  10. // This is the array for error handling
  11. var vError = [];
  12.  
  13. // We attach to every input field a little js
  14. function getForm() {
  15.  
  16. // Important: Our form has to got the "vform" id
  17. var form = document.getElementById(formid);
  18.  
  19. if (document.getElementsByTagName) {
  20. var vInput = document.getElementsByTagName("input");
  21. for (var vCount=0; vCount<vInput.length; vCount++)
  22. vInput[vCount].onblur = function() { return validateIt(this); }
  23. }
  24. }
  25.  
  26. // Refers to the function
  27. http = getHTTPObject();
  28.  
  29. function getHTTPObject() {
  30.  
  31. var xmlhttp;
  32.  
  33. /*@cc_on
  34.  
  35. @if (@_jscript_version >= 5)
  36. try {
  37. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  38. }catch(e){
  39. try{
  40. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  41. }catch(E){
  42. xmlhttp = false;
  43. }
  44. }
  45. @else
  46. xmlhttp = false;
  47. @end @*/
  48.  
  49. if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
  50. try {
  51. xmlhttp = new XMLHttpRequest();
  52. }catch(e){
  53. xmlhttp = false;
  54. }
  55. }
  56.  
  57. return xmlhttp;
  58.  
  59. }
  60.  
  61. // The main validation-function
  62. function validateIt(vInput) {
  63.  
  64. // Each input field's id
  65. vId = vInput.id;
  66. vValue = vInput.value;
  67.  
  68. // Separate the class attr of each input field
  69. getValue = vInput.className;
  70. if(getValue.indexOf(",") == -1 ) {
  71. vType = getValue;
  72. vRequired = "";
  73. } else {
  74. vRules = vInput.className.split(",");
  75. vRequired = vRules[0];
  76. vType = vRules[1];
  77. }
  78.  
  79. // The whole URL
  80. var url = vUrl + (vValue) + "&required=" + (vRequired) + "&type=" + (vType);
  81.  
  82. // And finally we send it to the url we specified
  83. http.open("GET", url, true);
  84.  
  85. // The handleHttpResponse is the function we call, when we have an
  86. // answer back from the PHP script
  87. http.onreadystatechange = handleHttpResponse;
  88. http.send(null);
  89.  
  90. }
  91.  
  92. // A function to handle the response from the PHP script
  93. function handleHttpResponse() {
  94.  
  95. if(http.readyState == 4) {
  96.  
  97. // Refering to the PHP script, for every validation we'll get
  98. // either true or false and apply some visual changes in order to
  99. // get the user focusing on each field whether it's ok or not
  100. // If one of the input fields contains an error, the submit button
  101. // will be disabled, until the error (that means all errors) are
  102. // solved
  103. if(http.responseText == "false") {
  104.  
  105. var sInput = document.getElementById(vId);
  106. var vButton = document.getElementById("submit");
  107.  
  108. document[vId].src = "http://localhost/cmsmade/img/false.png";
  109.  
  110. vButton.disabled = true;
  111. vError.push(vId);
  112.  
  113. }
  114.  
  115. if(http.responseText == "true") {
  116.  
  117. var sInput = document.getElementById(vId);
  118.  
  119. document[vId].src = "http://localhost/cmsmade/img/true.png";
  120.  
  121.  
  122. // We do a check if our element is in the error array, and if
  123. // so, we can delete it from the array
  124. if(vError.indexOf(vId) != -1) {
  125. var aId = vError.indexOf(vId);
  126. vError.splice(aId, 1);
  127. if(vError.length > 0) {
  128. var vButton = document.getElementById("submit");
  129. vButton.disabled = true;
  130. } else {
  131. var vButton = document.getElementById("submit");
  132. vButton.disabled = false;
  133. }
  134. }
  135. }
  136.  
  137. if(http.responseText == "none") {
  138.  
  139. var sInput = document.getElementById(vId);
  140. var vButton = document.getElementById("submit");
  141.  
  142. document[vId].src = "http://localhost/cmsmade/img/blank.gif";
  143. vButton.disabled = false;
  144.  
  145. }
  146.  
  147. }
  148. }


Otóz chcę zrobić żeby przycisk submit był dostępny dopiero gdy wszystkie wymagane pola będą uzupełnione poprawnie. Więc przy submit dałem disabled="disabled".
w javascript też dałem żeby przycisk się aktywował ale jest problem taki że gdy za pierwszym razem wszystko uzupełnię poprawnię to przycisk pozostaje nieaktywny. Dopiero gdy zrobię jakiś błąd w którymś polu i poprawię go przycisk się aktywuje czy jest ktoś w stanie mi pomóć

Dobra pozmieniałem trochę kod i już działa coś lepiej ale nadal to nie jest to
  1. // Load the getForm function while page is loading
  2. window.onload = getForm;
  3.  
  4. // Set this to your validation PHP script, default is "validate.php?value="
  5. var vUrl = "http://localhost/cmsmade/validate.php?value=";
  6.  
  7. // Set this to your form's id
  8. var formid = "vform";
  9.  
  10. // This is the array for error handling
  11. var vError = [];
  12.  
  13. // We attach to every input field a little js
  14. function getForm() {
  15.  
  16. // Important: Our form has to got the "vform" id
  17. var form = document.getElementById(formid);
  18.  
  19. if (document.getElementsByTagName) {
  20. var vInput = document.getElementsByTagName("input");
  21. for (var vCount=0; vCount<vInput.length; vCount++)
  22. vInput[vCount].onblur = function() { return validateIt(this); }
  23. }
  24. }
  25.  
  26. // Refers to the function
  27. http = getHTTPObject();
  28.  
  29. function getHTTPObject() {
  30.  
  31. var xmlhttp;
  32.  
  33. /*@cc_on
  34.  
  35. @if (@_jscript_version >= 5)
  36. try {
  37. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  38. }catch(e){
  39. try{
  40. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  41. }catch(E){
  42. xmlhttp = false;
  43. }
  44. }
  45. @else
  46. xmlhttp = false;
  47. @end @*/
  48.  
  49. if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
  50. try {
  51. xmlhttp = new XMLHttpRequest();
  52. }catch(e){
  53. xmlhttp = false;
  54. }
  55. }
  56.  
  57. return xmlhttp;
  58.  
  59. }
  60.  
  61. // The main validation-function
  62. function validateIt(vInput) {
  63.  
  64. // Each input field's id
  65. vId = vInput.id;
  66. vValue = vInput.value;
  67.  
  68. // Separate the class attr of each input field
  69. getValue = vInput.className;
  70. if(getValue.indexOf(",") == -1 ) {
  71. vType = getValue;
  72. vRequired = "";
  73. } else {
  74. vRules = vInput.className.split(",");
  75. vRequired = vRules[0];
  76. vType = vRules[1];
  77. }
  78.  
  79. // The whole URL
  80. var url = vUrl + (vValue) + "&required=" + (vRequired) + "&type=" + (vType);
  81.  
  82. // And finally we send it to the url we specified
  83. http.open("GET", url, true);
  84.  
  85. // The handleHttpResponse is the function we call, when we have an
  86. // answer back from the PHP script
  87. http.onreadystatechange = handleHttpResponse;
  88. http.send(null);
  89.  
  90. }
  91.  
  92. // A function to handle the response from the PHP script
  93. function handleHttpResponse() {
  94.  
  95. if(http.readyState == 4) {
  96.  
  97. // Refering to the PHP script, for every validation we'll get
  98. // either true or false and apply some visual changes in order to
  99. // get the user focusing on each field whether it's ok or not
  100. // If one of the input fields contains an error, the submit button
  101. // will be disabled, until the error (that means all errors) are
  102. // solved
  103. if(http.responseText == "false") {
  104.  
  105. var sInput = document.getElementById(vId);
  106. var vButton = document.getElementById("submit");
  107.  
  108. document[vId].src = "http://localhost/cmsmade/img/false.png";
  109.  
  110. vButton.disabled = true;
  111. vError.push(vId);
  112.  
  113. }
  114.  
  115. if(http.responseText == "true1") {
  116.  
  117. var sInput = document.getElementById(vId);
  118.  
  119. document[vId].src = "http://localhost/cmsmade/img/true.png";
  120.  
  121.  
  122.  
  123. }
  124.  
  125. if(http.responseText == "true2") {
  126.  
  127. var sInput = document.getElementById(vId);
  128.  
  129. document[vId].src = "http://localhost/cmsmade/img/true.png";
  130.  
  131.  
  132. }
  133.  
  134. if(http.responseText == "true3") {
  135.  
  136. var sInput = document.getElementById(vId);
  137.  
  138. document[vId].src = "http://localhost/cmsmade/img/true.png";
  139.  
  140. }
  141.  
  142. if(http.responseText == "true3" && "true2" && "true1") {
  143.  
  144. var sInput = document.getElementById(vId);
  145. var vButton = document.getElementById("submit");
  146.  
  147. vButton.disabled = false;
  148.  
  149. }
  150.  
  151.  
  152. if(http.responseText == "none") {
  153.  
  154. var sInput = document.getElementById(vId);
  155. var vButton = document.getElementById("submit");
  156.  
  157. document[vId].src = "http://localhost/cmsmade/img/blank.gif";
  158. vButton.disabled = false;
  159.  
  160. }
  161.  
  162. }
  163. }

a w php
  1. <?
  2.  
  3. /*
  4.  * This is the PHP script to validate the form over AJAX
  5.  * Validations types possible:
  6.  *
  7.  * - alpha
  8.  * - alphanum
  9.  * - date
  10.  * - email
  11.  * - number
  12.  * - url
  13.  *
  14.  */
  15.  
  16.  
  17. // Start the main function
  18. StartValidate();
  19.  
  20. function StartValidate() {
  21.  
  22. // Assign some var's for the requests
  23. $required = $_GET["required"];
  24. $type = $_GET["type"];
  25. $value = $_GET["value"];
  26.  
  27. // This is the function to check if a field is even required or not
  28. // So it's useful if you only want to check if it isn't empty
  29. validateRequired($required, $value, $type);
  30.  
  31. switch ($type) {
  32. case 'number':
  33. validateNumber($value);
  34. break;
  35. case 'alphanum':
  36. validateAlphanum($value);
  37. break;
  38. case 'email':
  39. validateEmail($value);
  40. break;
  41.  
  42. }
  43. }
  44.  
  45. // The function to check if a field is required or not
  46. function validateRequired($required, $value, $type) {
  47. if($required == "required") {
  48.  
  49. // Check if we got an empty value
  50. if($value == "") {
  51. echo "false";
  52. exit();
  53. }
  54. } else {
  55. if($value == "") {
  56. echo "none";
  57. exit();
  58. }
  59. }
  60. }
  61.  
  62. // I use regular expressions in order to check a field's input, you can
  63. // get most of them at the Regex Library at <a href="http://www.regexlib.com" target="_blank">http://www.regexlib.com</a>
  64. // There you can check your own regular expressions, too
  65.  
  66. // Validation of an Email Address
  67. function validateEmail($value) {
  68. if(ereg("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $value, $regs)) {
  69. echo "true1";
  70. } else {
  71. echo "false";
  72. }
  73. }
  74.  
  75. // Validation of characters and numbers
  76. function validateAlphanum($value) {
  77. if(ereg("[^\s0-9]", $value, $regs)) {
  78. echo "true2";
  79. } else {
  80. echo "false";
  81. }
  82. }
  83.  
  84. // Validation of numbers
  85. function validateNumber($value) {
  86. if(ereg("^[0-9]+$", $value, $regs)) {
  87. echo "true3";
  88. } else {
  89. echo "false";
  90. }
  91. }
  92.  
  93.  
  94. ?>

teraz submit robi się aktywny gdy jest zaznaczona wartość true3 więć nie wiem o co chodzi tak jakby sprawdzał czy tylko wartość true3 jest i wtedy aktywował submita a chciałbym żeby przy wszystkich dopiero był aktywny