Chcę zrobić formularz rejestracji informujący usera czy wprowadził poprawne dane w zdarzeniu onblur dokładnie coś takiego jak tu:
http://www.forum.optymalizacja.com/index.p...mp;coppa_pass=1


To co wymyśliłem:
[JAVASCRIPT] pobierz, plaintext
  1. <script type="text/javascript">
  2. function ajax_check(input_value, input_name) {
  3. //dane poprawne sprawdzane alertem
  4.  
  5. $.post("ajax_check.php",{checker:input_value, checker_name:input_name}, function(data) {
  6.  
  7. if(data) {
  8. $(this).removeClass('input').addClass('input_error'); //remove old class from input field and add error class
  9. $('div#error_'+input_name).css({'display' : 'block'});
  10. $('div#error_'+input_name).text(data);
  11. $('#'+input_name+'_cross').css({'display' : 'block'});
  12. }
  13. else {
  14. $(this).removeClass('input input_error').addClass('input_ok'); //remove old class from input field and add error class
  15. $('#'+input_name+'_tick').css({'display' : 'block'});
  16. }
  17.  
  18. });
  19.  
  20. };
  21. </script>
[JAVASCRIPT] pobierz, plaintext



  1. <form name="login" id="login" action="index.php?p=register" method="post">
  2. <h1 class="log">Zarejestruj nowego użytkownika</h1><br>
  3.  
  4. <label><strong>Login:</strong></label>
  5. <input class="input" name="konto" type="text" value="" maxlength="80" onblur="ajax_check(this.value, this.name)" />
  6. <div id="error_konto">login</div>
  7. <img src="img/aff_cross.gif" id="konto_cross" alt="cross" class="image_error">
  8. <img src="img/aff_tick.gif" id="konto_tick" alt="tick" class="image_ok">
  9. <br>
  10.  
  11. <label><strong>Hasło:</strong></label>
  12. <input class="input" name="password" type="password" value="" maxlength="14" onblur="ajax_check(this.value, this.name)"/>
  13. <div id="error_password">pass</div>
  14. <img src="img/aff_cross.gif" id="password_cross" alt="cross" class="image_error">
  15. <img src="img/aff_tick.gif" id="password_tick" alt="tick" class="image_ok">
  16. <br>
  17.  
  18. <strong>Powtórz haslo:</strong></label>
  19. <input class="input" name="password2" type="password" value="" maxlength="14" onblur="ajax_check(this.value, this.name)"/>
  20. <div id="error_password2">pass2</div><img src="img/aff_cross.gif" id="password2_cross" alt="cross" class="image_error">
  21. <img src="img/aff_tick.gif" id="password2_tick" alt="tick" class="image_ok"><br>
  22.  
  23. <label><strong>Podaj e-mail:</strong></label>
  24. <input class="input" name="email" type="text" value="" onblur="ajax_check(this.value, this.name)" />
  25. <div id="error_email">email</div>
  26. <img src="img/aff_cross.gif" id="email_cross" alt="cross" class="image_error">
  27. <img src="img/aff_tick.gif" id="email_tick" alt="tick" class="image_ok">
  28. <br>
  29.  
  30. <br>
  31. <input type="submit" value="Zarejestruj" class="button" />
  32. <input type="submit" value="Cancel" class="button" />
  33. </form>


  1. //plik ajax_check.php
  2. require_once('functions.php');
  3. $checker = clean($_POST['checker']);
  4. $checker_name = clean($_POST['checker_name']);
  5.  
  6. switch($checker_name) {
  7. case 'konto':
  8. if (strlen($checker) < 1 && strlen($checker) > 80) {
  9. echo 'Nazwa użytkonwika musi mieć od 1 do 80 znaków.';
  10. break;
  11. }
  12. $ile =mysql_query("SELECT * FROM `users` WHERE login = '$konto'");
  13. $ile = mysql_num_rows($ile);
  14. if ($ile==0) {
  15. echo '';
  16. }
  17. else {
  18. echo 'Użytkownik ' .$checker. ' już istnieje wybierz inną nazwę.';
  19. }
  20. break;
  21.  
  22. case 'password':
  23. $_SESSION[$pass] = $checker;
  24. if (!checkUserPass($checker)) {
  25. echo 'Nazwa użytkonwika musi mieć od 3 do 14 znaków. I może się składać tylko ze znaków alfanumerycznych.';
  26. }
  27. else echo '';
  28. break;
  29.  
  30. case 'password2':
  31. if ($checker !== $_SESSION[$pass]) {
  32. echo 'Hasła nie są takie same.';
  33. }
  34. else echo '';
  35. break;
  36.  
  37. case 'email':
  38. if (!filter_var(trim($checker), FILTER_VALIDATE_EMAIL)) {
  39. echo 'Adres e-mail ma niepoprawny format.';
  40. }
  41. else echo '';
  42. break;
  43.  
  44. default:
  45. echo 'Formularz zawiera niepoprawne lub niekompletne dane.';
  46.  
  47. break;
  48. }


I jeszcze css nie mieszczący się w pierwszym poście
  1. /* FORMAULARZE I INPUTY */
  2. .input {
  3. border: 1px solid #006;
  4. background: #ffc;
  5. width: 330px;
  6. }
  7.  
  8. .input:hover {
  9. border: 1px solid #f00;
  10. background: #ff6;
  11. width: 330px;
  12. }
  13.  
  14. .input_error {
  15. border: 1px solid #FF0000;
  16. background: #ffc;
  17. width: 330px;
  18. }
  19.  
  20. .input_error:hover {
  21. border: 1px solid #FF0000;
  22. background: #ff6;
  23. width: 330px;
  24. }
  25.  
  26. .input_ok {
  27. border: 1px solid #00FF00;
  28. background: #ffc;
  29. width: 330px;
  30. }
  31.  
  32. .input_ok:hover {
  33. border: 1px solid #00FF00;
  34. background: #ff6;
  35. width: 330px;
  36. }
  37.  
  38. .image_error {
  39. display: none;
  40. position: relative;
  41. left: 495px;
  42. bottom: 35px;
  43. }
  44.  
  45. .image_ok {
  46. position: relative;
  47. left: 495px;
  48. bottom: 35px;
  49. }
  50.  
  51. label {
  52. display: block;
  53. width: 150px;
  54. float: left;
  55. margin: 2px 4px 6px 4px;
  56. text-align: right;
  57. }
  58. br { clear: left; }
  59.  
  60. div#error_konto, div#error_password, div#error_password2, div#error_email {
  61. display: none;
  62. border: 1px solid #FF0000;
  63. background: #FF9999;
  64. width: 328px;
  65. position: relative;
  66. left: 158px;
  67. bottom: 45px;
  68. clear: both;
  69. }


ok nieważne już działa zła ścieżka do pliku php i kilka innych drobiazgów