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
<?php
public $login;
public $haslo;
public function Style() {
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="title" content="AA" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="scr.js" type="text/javascript"></script>
<link rel="stylesheet" href="styles/style.css" type="text/css" media="screen" />
<script src="scr.js" type="text/javascript"></script>
</head>';
}
public function LoginForm() {
echo '<form method="POST" action="index.php">
<div id="login_form">
<fieldset>
<legend>Logowanie do Sytemu </legend>
<div>
<label for="fMail">Login</label>
<input id="login" name="login" class="text" type="text" />
</div>
<div>
<label for="fMail">Hasło</label>
<input id="haslo" name="haslo" class="text" type="text" />
</div>
<div>
<input id="submit" name="submit" rel="#yesno" class="submit" type="submit" value="Zaloguj" />
<INPUT name="submitted" type="hidden" value="TRUE" >
</div>
</fieldset>
</div>
</form>';
?>
<script>
$(document).ready(function() {
var triggers = $(".submit").overlay({
mask: {
color: '#ebecff',
loadSpeed: 200,
opacity: 0.9
},
closeOnClick: false
});
var buttons = $("#yesno button").click(function(e) {
var yes = buttons.index(this) === 0;
});
});
</script>
<?php
}
public function StartLogin(Mysqli $db,$param1,$param2) {
$this->login = $param1;
$this->haslo = $param2;
if(empty($this->login)) {
$this->errors[]= '<p>empty login</p>';
} else {
$l = (trim($this->login));
}
if(empty($this->haslo)) {
$this->errors[]= '<p>empty haslo</p>';
} else {
$h= (trim($this->haslo));
}
if(empty($this->errors)) {
$stmt = $db -> stmt_init();
$query="SELECT name, surename FROM accounts WHERE username=? AND passwd=?";
if (($stmt = $db->prepare($query))) {
$stmt->bind_param('ss', $username, $passwd);
$username = $l;
$passwd = $h;
if ($stmt->execute()) {
$stmt->store_result();
$stmt->bind_result($name_result, $nazwisko_result);
while($stmt->fetch()) {
echo $name_result . ' - ' . $nazwisko_result ;
}
$stmt->close();
} else {
echo "Execute failed: (" . $db->errno . ") " . $db->error;
}
} else {
echo "Prepare failed: (" . $db->errno . ") " . $db->error;
}
$db->close();
} else {
$this->errors[] = '<p>Nieprawidłowe dane do zalogowania się</p>';
}
?>
<div class="modal" id="yesno">
<h2>System</h2>
<?php
foreach ($this->errors as $msg) {
}
?>
<p><button class="close"> Zamknij okno </button></p>
</div>
<?php
}
}
?>
Wywołuję:
<?php
include_once("class.System.php");
include_once("class.DB.php");
$b = new DB;
$a->Style();
$a->LoginForm();
if(isset($_POST['submitted'])) {
$login_string=(string)$_POST['login'];
$haslo_string=(string)$_POST['haslo'];
$a->StartLogin($b->connect(),$login_string,$haslo_string);
}
?>
Ten post edytował barthezpl 20.03.2012, 09:25:38