|
|
|
Zaklady
|
Majax
|
Generovani formularu
|
Forms Validation
Table of Contents
Formulare - validace
Pokud ma formular nastavenou v html tridu majaxForm, je automaticky pridan mezi formulare, ktere budou validovany. Pokud tuto tridu nema, je mozne ho pridat pomoci funkce Majax.Form.add.
Nasledujici kus kodu ukazuje jednoduchy formular pro pro registraci uzivatele. Je nezbytne, aby mel jednoznacne id.
<table>
<tr>
<td>
<form id="registrationFormA" class="majaxForm" action="">
<dl>
<dt>Username:</dt>
<dd><input type="text" name="userName" /></dd>
<dt>Password:</dt>
<dd><input type="password" name="newPass1" /></dd>
<dt>Confirm Password:</dt>
<dd><input type="password" name="newPass2" /></dd>
</dl>
<div><input type="submit" value="Send" /></div>
</form>
</td>
<td>
</td>
</tr>
</table>
Pokud je formular odeslan uzivatelem, je nejdrive zaslan pozadavek na URL specifikovanou v atributu action, kde musi byt funkce, ktera tento pozadavek zpracuje.
require_once('majax.php');
Majax::Form()->register('registrationFormA', 'processForm');
{
$error = false;
if (!$arg['userName']) {
Majax::Form()->addAlert('Please, fill username.');
$error = true;
}
if (!$arg['newPass1'] || !$arg['newPass2']) {
Majax::Form()->addAlert('Please, fill password.');
$error = true;
}
if ($arg['newPass1'] != $arg['newPass2']) {
Majax::Form()->addAlert('Passwords are diferent.');
$error = true;
}
if (strlen($arg['newPass1']) <
8) {
Majax::Form()->addAlert('Password too short.');
$error = true;
}
}
|
|
|
Zaklady
|
Majax
|
Generovani formularu
|
Documentation generated on Tue, 23 Feb 2010 10:23:55 +0100 by phpDocumentor 1.4.3