Witam, mam następujący kod:

index.php:

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $('#wait_0').hide();
  4. $('#wait_1').hide();
  5. $('#wait_2').hide();
  6. $('#kod_pocztowy').bind("keyup change", function(e) {
  7. $('#wait_0').show();
  8. $('#result_0').hide();
  9. $('#result_1').hide();
  10. $('#result_2').hide();
  11. $.post("xxxx_test.php", {
  12. func: "postcode",
  13. postcode_var: $('#kod_pocztowy').val()
  14. }, function(response){
  15. $('#result_0').fadeOut();
  16. setTimeout("finishAjaxPostCode('result_0', '"+escape(response)+"')", 400);
  17. });
  18. return false;
  19. });
  20. });
  21.  
  22. function finishAjaxPostCode(id, response){
  23. $('#wait_0').hide();
  24. $('#'+id).html(unescape(response));
  25. $('#'+id).fadeIn();
  26. }
  27.  
  28. function finishAjax(id, response) {
  29. $('#wait_1').hide();
  30. $('#'+id).html(unescape(response));
  31. $('#'+id).fadeIn();
  32. }
  33.  
  34. function finishAjax_tier_three(id, response) {
  35. $('#wait_2').hide();
  36. $('#'+id).html(unescape(response));
  37. $('#'+id).fadeIn();
  38. }


  1. if(array_key_exists('FormRegisterEnd', $_POST)){
  2.  
  3. $city = safeEncode($_POST['miasto']);
  4. $city = mb_strtolower($city,"UTF-8");
  5. $city = mb_ucfirst($city,"UTF-8");
  6.  
  7. $postcode = safeEncode($_POST['kod_pocztowy']);
  8.  
  9. $street = safeEncode($_POST['ulica']);
  10. $street = mb_strtolower($street,"UTF-8");
  11. $street = mb_ucfirst($street,"UTF-8");
  12.  
  13. $errors = array();
  14.  
  15. if($postcode == ''){
  16. $komunikat2 ='Sprawdź błędy na stronie i je popraw:';
  17. $errors['kod_pocztowy'] = '<div style=padding-top:2px><img src=/images/alert.png></div>Błąd: Nie wpisano kodu pocztowego.';
  18. }
  19.  
  20. if($city == ''){
  21. $komunikat2 ='Sprawdź błędy na stronie i je popraw:';
  22. $errors['miasto'] = '<div style=padding-top:2px><img src=/images/alert.png></div>Błąd: Nie wpisano miasta.';
  23. }
  24.  
  25. if($street == ''){
  26. $komunikat2 ='Sprawdź błędy na stronie i je popraw:';
  27. $errors['ulica'] = '<div style=padding-top:2px><img src=/images/alert.png></div>Błąd: Nie wpisano adresu.';
  28. }
  29.  
  30.  
  31. if(empty($errors)){
  32. print ('nie ma błędów dodajemy do bazy');
  33. }
  34. }


  1. <form method="post" name="FormRegisterEnd">
  2. <div>
  3. <div style="padding:30px;">
  4. <div style="min-width:120px; display:inline; float:left; font-weight:bold; padding-top:8px;">*Kod pocztowy:</div>
  5. <div style="display:inline; width:400px; margin-left:30px;">
  6. <input type="text" name="kod_pocztowy" value="<?php if(isset($postcode)){print(''.zabezpiecz($_POST['kod_pocztowy']).'');}?>" style="width:350px;" class="input_search" id="kod_pocztowy" autocomplete="off">
  7. </div>
  8. <div style="width:400px; margin-top:-50px; margin-left:535px; display:inline; float:left;" id="kod_pocztowyerr"></div>
  9. </div>
  10. </div>
  11.  
  12. <span id="wait_0"><img alt="czekaj" src="/images/loader.gif"/></span>
  13. <span id="result_0" style="display: none;"></span>
  14.  
  15. <span id="wait_1" style="display: none; margin-left:150px;"><img alt="czekaj" src="/images/loader.gif"/></span>
  16. <span id="result_1" style="display: none;"></span>
  17.  
  18. <span id="wait_2" style="display: none;"><img alt="czekaj" src="/images/loader.gif"/></span>
  19. <span id="result_2" style="display: none;"></span>
  20.  
  21.  
  22. <div style="width:880px; margin-top:30px;">
  23. <div style="padding:30px;">
  24. <div style="min-width:250px; display:inline; font-weight:bold;"></div>
  25. <div style="display:inline; width:320px; margin-left:430px;">
  26. <input type="submit" name="FormRegisterEnd" class="button" value="Zakończ">
  27. </div>
  28. </div>
  29. </div>
  30. </form>



teraz w pliku xxxx_test.php:

  1. if($_POST['func'] == "postcode" && isset($_POST['func'])){
  2. $postcode_var = $_POST['postcode_var'];
  3. postcode($_POST['postcode_var']);
  4. }
  5.  
  6. function postcode($postcode_var){
  7. <div>
  8. <div style="padding:30px;">
  9. <div style="min-width:120px; display:inline; float:left; font-weight:bold; padding-top:8px;">*Miasto:</div>
  10. <div style="display:inline; width:400px; margin-left:30px;">
  11.  
  12. <div id="suggest" style="margin-left:150px;">
  13. <input type="text" name="miasto" style="width:350px;" class="input_search" id="miasto" value="'); if(isset($city)){print(''.zabezpiecz($_POST['miasto']).'');}echo('" onkeyup="suggest(this.value);" onblur="fill();" autocomplete="off">
  14. <div class="suggestionsBox" id="suggestions" style="display: none; width:375px; margin-top:-3px;">
  15. <div class="suggestionList" id="suggestionsList"></div>
  16. </div>
  17. </div>
  18.  
  19. </div>
  20. <div style="width:400px; margin-top:-50px; margin-left:535px; display:inline; float:left;" id="miastoerr"></div>
  21. </div>
  22. </div>
  23. ');
  24. }
  25.  
  26. if($_POST['func'] == "city" && isset($_POST['func'])) {
  27. city($_POST['city_var']);
  28. }
  29.  
  30. function city($city_var, $postcode){
  31. //zapytanie do bazy mysql..
  32. echo('
  33. <div>
  34. <div style="padding:30px;">
  35. <div style="min-width:120px; display:inline; float:left; font-weight:bold; padding-top:8px;">*Adres (ul. i nr.):</div>
  36. <div style="display:inline; width:400px; margin-left:30px;">');
  37. if(mysql_num_rows($result)>0){
  38. echo('
  39. <div id="suggest2" style="margin-left:150px;">
  40. <input type="text" name="ulica" value="');if(isset($street)){print(''.zabezpiecz($_POST['ulica']).'');}echo('" style="width:350px;" class="input_search" id="ulica" onkeyup="suggest2(this.value);" onblur="insertValue();" autocomplete="off">
  41. <div class="suggestionsBox" id="suggestions2" style="display:none; position:static; width:375px; margin-top:-3px;">
  42. <div class="suggestionList" id="suggestionsList2"></div>
  43. </div>
  44. </div>');
  45. }else{
  46. echo('<input type="text" name="ulica" value="');if(isset($street)){print(''.zabezpiecz($_POST['ulica']).'');}echo('" style="width:350px;" class="input_search" id="ulica" autocomplete="off">');
  47. }
  48. echo('
  49. </div>
  50. <div style="width:400px; margin-top:-50px; margin-left:535px; display:inline; float:left;" id="ulicaerr"></div>
  51. </div>
  52. </div>');
  53. }
  54.  
  55. if($_POST['func'] == "adres" && isset($_POST['func'])){
  56. adres($_POST['adres_var']);
  57. }
  58.  
  59. function adres($adres_var, $postcode){
  60. $postcode = $_POST['postcode'];
  61.  
  62. //tu zapytanie do bazy...
  63.  
  64. echo('
  65. <div>
  66. <div style="padding:30px;">
  67. <div style="min-width:120px; display:inline; float:left; font-weight:bold; padding-top:8px;">Województwo:</div>
  68. <div style="display:inline; width:400px; margin-left:30px;">');
  69. echo '<select name="woj" id="woj" class="input_search" style="width:380px;">';
  70. while($pokazWoj = mysql_fetch_array($result)){
  71. echo '<option value="'.$pokazWoj['woj'].'" disabled="disabled" selected="selected">'.$pokazWoj['woj'].'</option>';
  72. }
  73. echo '</select> ';
  74.  
  75. echo('
  76. </div>
  77. <div style="width:400px; margin-top:-50px; margin-left:535px; display:inline; float:left;" id="wojerr"></div>
  78. </div>
  79. </div>
  80. ');
  81. }



Zamierzenie które chcę osiągnąć to:
1 - Nie wpisano kodu pocztowego wyświetli od razu błąd bez wciskania submita zakończ.
2 . Po wpisaniu poprawnego kodu pocztowego pojawia się poniżej pole miasto (tak teraz się robi) ale jeżeli wcisnę submit "zakończ" wraca do początku tylko zapamięta w polu kod pocztowy ten kod ale nie zatrzymuje ramki z polem miasto.
3. Tak ma się tworzyć dla pozostałych pól.

Jak to działa w praktyce proszę zobaczyć tutaj: zobacz link