Witam.
Bez dodatków jquery, formularz spełnia swoje założenia("formularz nie jest jeszcze ukończony w 100%") natomiast dodaje okno dialogowe, aby wyrzucało błędy na ekran. Do okna przekazywana jest tablica errors, która zawiera błędy z niepoprawnie wypełnionego formularza. I teraz, uzupełniam formularz, a do okna dialogowego przekazywana jest całkowicie wypełniona tablica, wytłumacie laikowi co zrobić aby jquery sprawdzało formularz po wciśniećiu buttona a nie po załadowaniu strony
  1. <?php
  2.  
  3. class System {
  4.  
  5. public $errors=array();
  6.  
  7. public $login;
  8.  
  9. public $haslo;
  10.  
  11. public function Style() {
  12.  
  13. echo '
  14.  
  15. <head>
  16.  
  17. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  18.  
  19. <meta name="title" content="AA" />
  20.  
  21. <script src="http://code.jquery.com/jquery-latest.js"></script>
  22.  
  23. <script src="scr.js" type="text/javascript"></script>
  24.  
  25. <link rel="stylesheet" href="styles/style.css" type="text/css" media="screen" />
  26.  
  27. <script src="scr.js" type="text/javascript"></script>
  28.  
  29. </head>';
  30.  
  31. }
  32.  
  33. public function LoginForm() {
  34.  
  35. echo '<form method="POST" action="index.php">
  36.  
  37. <div id="login_form">
  38.  
  39. <fieldset>
  40.  
  41. <legend>Logowanie do Sytemu </legend>
  42.  
  43. <div>
  44.  
  45. <label for="fMail">Login</label>
  46.  
  47. <input id="login" name="login" class="text" type="text" />
  48.  
  49. </div>
  50.  
  51. <div>
  52.  
  53. <label for="fMail">Hasło</label>
  54.  
  55. <input id="haslo" name="haslo" class="text" type="text" />
  56.  
  57. </div>
  58.  
  59. <div>
  60.  
  61. <input id="submit" name="submit" rel="#yesno" class="submit" type="submit" value="Zaloguj" />
  62.  
  63. <INPUT name="submitted" type="hidden" value="TRUE" >
  64.  
  65. </div>
  66.  
  67. </fieldset>
  68.  
  69. </div>
  70.  
  71. </form>';
  72.  
  73. ?>
  74.  
  75. <script>
  76.  
  77. $(document).ready(function() {
  78.  
  79. var triggers = $(".submit").overlay({
  80.  
  81. mask: {
  82.  
  83. color: '#ebecff',
  84.  
  85. loadSpeed: 200,
  86.  
  87. opacity: 0.9
  88.  
  89. },
  90.  
  91. closeOnClick: false
  92.  
  93. });
  94.  
  95. var buttons = $("#yesno button").click(function(e) {
  96.  
  97. var yes = buttons.index(this) === 0;
  98.  
  99. });
  100.  
  101. });
  102.  
  103. </script>
  104.  
  105. <?php
  106.  
  107. }
  108.  
  109. public function StartLogin(Mysqli $db,$param1,$param2) {
  110.  
  111. $this->login = $param1;
  112.  
  113. $this->haslo = $param2;
  114.  
  115. if(empty($this->login)) {
  116.  
  117. echo '<br>';
  118.  
  119. $this->errors[]= '<p>empty login</p>';
  120.  
  121. } else {
  122.  
  123. $l = (trim($this->login));
  124.  
  125. }
  126.  
  127. if(empty($this->haslo)) {
  128.  
  129. echo '<br>';
  130.  
  131. $this->errors[]= '<p>empty haslo</p>';
  132.  
  133. } else {
  134.  
  135. $h= (trim($this->haslo));
  136.  
  137. }
  138.  
  139. if(empty($this->errors)) {
  140.  
  141. $stmt = $db -> stmt_init();
  142.  
  143. $query="SELECT name, surename FROM accounts WHERE username=? AND passwd=?";
  144.  
  145. if (($stmt = $db->prepare($query))) {
  146.  
  147. $stmt->bind_param('ss', $username, $passwd);
  148.  
  149. $username = $l;
  150.  
  151. $passwd = $h;
  152.  
  153. if ($stmt->execute()) {
  154.  
  155. $stmt->store_result();
  156.  
  157. echo $stmt->num_rows;
  158.  
  159. $stmt->bind_result($name_result, $nazwisko_result);
  160.  
  161. while($stmt->fetch()) {
  162.  
  163. echo $name_result . ' - ' . $nazwisko_result ;
  164.  
  165. }
  166.  
  167. $stmt->close();
  168.  
  169. } else {
  170.  
  171. echo "Execute failed: (" . $db->errno . ") " . $db->error;
  172.  
  173. }
  174.  
  175. } else {
  176.  
  177. echo "Prepare failed: (" . $db->errno . ") " . $db->error;
  178.  
  179. }
  180.  
  181. $db->close();
  182.  
  183. } else {
  184.  
  185. echo '<br>';
  186.  
  187. $this->errors[] = '<p>Nieprawidłowe dane do zalogowania się</p>';
  188.  
  189. }
  190.  
  191. ?>
  192.  
  193. <div class="modal" id="yesno">
  194.  
  195. <h2>System</h2>
  196.  
  197. <?php
  198. foreach ($this->errors as $msg) {
  199. echo $msg;
  200. echo $this->login;
  201. }
  202. ?>
  203.  
  204. <p><button class="close"> Zamknij okno </button></p>
  205.  
  206. </div>
  207. <?php
  208.  
  209. }
  210.  
  211. }
  212.  
  213. ?>


Wywołuję:
  1. <?php
  2.  
  3. include_once("class.System.php");
  4.  
  5. include_once("class.DB.php");
  6.  
  7. $b = new DB;
  8.  
  9. $a = new System;
  10.  
  11. $a->Style();
  12.  
  13. $a->LoginForm();
  14.  
  15. if(isset($_POST['submitted'])) {
  16.  
  17. $login_string=(string)$_POST['login'];
  18.  
  19. $haslo_string=(string)$_POST['haslo'];
  20.  
  21. $a->StartLogin($b->connect(),$login_string,$haslo_string);
  22.  
  23. }
  24.  
  25. ?>