Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][AJAX]Integracja jQueryDialog z PHP
Forum PHP.pl > Forum > Przedszkole
northwest
Witam serdecznie,
mam taki kod:
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <link rel="stylesheet" href="http://jqueryui.com/themes/base/jquery.ui.all.css">
  6. <script src="http://jqueryui.com/jquery-1.4.4.js"></script>
  7. <script src="http://jqueryui.com/external/jquery.bgiframe-2.1.2.js"></script>
  8. <script src="http://jqueryui.com/ui/jquery.ui.core.js"></script>
  9. <script src="http://jqueryui.com/ui/jquery.ui.widget.js"></script>
  10. <script src="http://jqueryui.com/ui/jquery.ui.mouse.js"></script>
  11. <script src="http://jqueryui.com/ui/jquery.ui.button.js"></script>
  12. <script src="http://jqueryui.com/ui/jquery.ui.draggable.js"></script>
  13. <script src="http://jqueryui.com/ui/jquery.ui.position.js"></script>
  14. <script src="http://jqueryui.com/ui/jquery.ui.resizable.js"></script>
  15. <script src="http://jqueryui.com/ui/jquery.ui.dialog.js"></script>
  16. <script src="http://jqueryui.com/ui/jquery.effects.core.js"></script>
  17. <script src="http://jqueryui.com/ui/jquery.effects.blind.js"></script>
  18. <script src="http://jqueryui.com/ui/jquery.effects.explode.js"></script>
  19. <link rel="stylesheet" href="http://jqueryui.com/demos/demos.css">
  20. <style>
  21. body { font-size: 62.5%; }
  22. label, input { display:block; }
  23. input.text { margin-bottom:12px; width:95%; padding: .4em; }
  24. fieldset { padding:0; border:0; margin-top:25px; }
  25. h1 { font-size: 1.2em; margin: .6em 0; }
  26. div#users-contain { width: 350px; margin: 20px 0; }
  27. div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
  28. div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
  29. .ui-dialog .ui-state-error { padding: .3em; }
  30. .validateTips { border: 1px solid transparent; padding: 0.3em; }
  31. </style>
  32. <script>
  33. // increase the default animation speed to exaggerate the effect
  34. $.fx.speeds._default = 1000;
  35. $(function() {
  36. $( "#dialog" ).dialog({
  37. autoOpen: false,
  38. height: 240,
  39. width: 240,
  40. show: "explode",
  41. modal: true,
  42. hide: "explode"
  43. });
  44.  
  45. $( "#opener" ).click(function() {
  46. $("#dialog").dialog( "open" );
  47. return false;
  48. });
  49. });
  50. </script>
  51.  
  52.  
  53. $(function() {
  54. // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
  55. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  56.  
  57. var name = $( "#name" ),
  58. email = $( "#email" ),
  59. password = $( "#password" ),
  60. allFields = $( [] ).add( name ).add( email ).add( password ),
  61. tips = $( ".validateTips" );
  62.  
  63. function updateTips( t ) {
  64. tips
  65. .text( t )
  66. .addClass( "ui-state-highlight" );
  67. setTimeout(function() {
  68. tips.removeClass( "ui-state-highlight", 1500 );
  69. }, 500 );
  70. }
  71.  
  72. function checkLength( o, n, min, max ) {
  73. if ( o.val().length > max || o.val().length < min ) {
  74. o.addClass( "ui-state-error" );
  75. updateTips( "Length of " + n + " must be between " +
  76. min + " and " + max + "." );
  77. return false;
  78. } else {
  79. return true;
  80. }
  81. }
  82.  
  83. function checkRegexp( o, regexp, n ) {
  84. if ( !( regexp.test( o.val() ) ) ) {
  85. o.addClass( "ui-state-error" );
  86. updateTips( n );
  87. return false;
  88. } else {
  89. return true;
  90. }
  91. }
  92.  
  93. $( "#dialog-form" ).dialog({
  94. autoOpen: false,
  95. height: 300,
  96. width: 350,
  97. modal: true,
  98. buttons: {
  99. "Create an account": function() {
  100. var bValid = true;
  101. allFields.removeClass( "ui-state-error" );
  102.  
  103. bValid = bValid && checkLength( name, "username", 3, 16 );
  104. bValid = bValid && checkLength( email, "email", 6, 80 );
  105. bValid = bValid && checkLength( password, "password", 5, 16 );
  106.  
  107. bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
  108. // From jquery.validate.js (by joern), contributed by Scott Gonzalez: <a href="http://projects.scottsplayground.com/email_address_validation/" target="_blank">http://projects.scottsplayground.com/email...ess_validation/</a>
  109. bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com" );
  110. bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
  111.  
  112. if ( bValid ) {
  113.  
  114. $( "#users tbody" ).append( "<tr>" +
  115. "<td>" + name.val() + "</td>" +
  116. "<td>" + email.val() + "</td>" +
  117. "<td>" + password.val() + "</td>" +
  118. "</tr>" );
  119. $( this ).dialog( "close" );
  120. }
  121. },
  122. Cancel: function() {
  123. $( this ).dialog( "close" );
  124. }
  125. },
  126. close: function() {
  127. allFields.val( "" ).removeClass( "ui-state-error" );
  128. }
  129. });
  130.  
  131. $( "#create-user" )
  132. .button()
  133. .click(function() {
  134. $( "#dialog-form" ).dialog( "open" );
  135. });
  136. });
  137. </script>
  138. </head>
  139. <body>
  140. <?php
  141. echo"mam $_POST[abc]";
  142.  
  143. print_r($_POST);
  144. print_r($_GET);
  145. ?>
  146. <div class="demo">
  147.  
  148. <div id="dialog" title="Basic dialog">
  149. <form action="" type="post">
  150. <input type="text" name="abc">
  151. <input type="submit">
  152. </form>
  153.  
  154. <p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
  155. </div>
  156.  
  157. <button id="opener">Open Dialog</button>
  158. <a href="#" id="opener">text</a>
  159. </div><!-- End demo -->
  160.  
  161. <div id="dialog-form" title="Create new user">
  162. <p class="validateTips">All form fields are required.</p>
  163.  
  164. <form method = "post">
  165. <label for="name">Name</label>
  166. <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
  167. <label for="email">Email</label>
  168. <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
  169. <label for="password">Password</label>
  170. <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
  171. </form>
  172. </div>
  173.  
  174. <div class="demo-description">
  175. <p>Dialogs may be animated by specifying an effect for the show and/or hide properties. You must include the individual effects file for any effects you would like to use.</p>
  176.  
  177.  
  178. <div id="users-contain" class="ui-widget">
  179. <h1>Existing Users:</h1>
  180. <table id="users" class="ui-widget ui-widget-content">
  181. <thead>
  182. <tr class="ui-widget-header ">
  183. <th>Name</th>
  184. <th>Email</th>
  185. <th>Password</th>
  186. </tr>
  187. </thead>
  188. <tbody>
  189. <tr>
  190. <td>John Doe</td>
  191. <td>john.doe@example.com</td>
  192. <td>johndoe1</td>
  193. </tr>
  194. </tbody>
  195. </table>
  196. </div>
  197. <button id="create-user">Create new user</button>
  198. </div><!-- End demo-description -->
  199.  
  200. </body>
  201. </html>




Co trzeba zrobić, ażeby ten skrypt wysyłał dane w POST lub GET i od¶wierzył tabelkę?
To co teraz jest, nie bardzo działa
w print_r($_POST) i print_r($_GET) nie zwraca mi żadnych wyników Wiecie może co jest nie tak?

wyczytałem że formularze wysyła się czym¶ takim:
  1. if ( bValid ) {
  2. $.post("aktualnyplik.php", { name: $('#name').attr("value"),
  3. mail: $('#email').attr("value")}


ale to nie bardzo działa sad.gif


Northwest
wookieb
1) Nie zapoznajesz się z konsol± błędów
2) A skoro się z ni± nie zapoznajsz to komunikatu błędu nie podajesz nam.
northwest

udało mi się smile.gif
if ( bValid ) {
$.post('test.php', { 'name' : $('#name').val(),'email' : $('#email').val(),'send': 'ok'});

mam takie pytanko, co zrobić żeby od¶wieżyć t± tabelkę: id="users" po zapisie?
wookieb
http://api.jquery.com/jQuery.post/
northwest
znalazłem taki sposób:
  1. $( this ).dialog( "close" );
  2. $("#users").toggle('slow');
  3. $('#users').load('slow').load();
  4. $("#users").load("dane.php");
  5. $("#users").toggle('slow');


tabelka:
  1. <table id="users" class="ui-widget ui-widget-content">
  2. <thead>
  3. <tr class="ui-widget-header ">
  4. <th>Name</th>
  5. <th>Email</th>
  6. </tr>
  7. </thead>
  8. <tbody>
  9. <tr>
  10. <?php
  11. include"dane.php";
  12. ?>
  13. </tr>
  14. </tbody>
  15. </table>

  1. $lista = file('baza.txt');
  2. foreach ($lista as $userek)
  3. {
  4. $tuser = explode('|',$userek);
  5. echo"<tr> <td>$tuser[0]</td>";
  6. echo"<td>$tuser[1]</td></tr> ";
  7. }


po wykonaniu zapisu do pliku ramka się od¶wieża, ale nie wczytuje nowych danych... sad.gif dlaczego??
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.