forked from nette/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform-example-en.php
47 lines (31 loc) · 986 Bytes
/
form-example-en.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require 'Nette/loader.php';
use Nette\Forms\Form;
$form = new Form;
$form->addText('name', 'Name:')
->setRequired('Please fill your name.');
$form->addInteger('age', 'Age:')
->setRequired()
->addRule(Form::RANGE, 'You must be older %d years and be under %d.', [18, 120]);
$form->addPassword('password', 'Password:')
->setRequired('Pick a password')
->addRule(Form::MIN_LENGTH, 'Your password has to be at least %d long', 3);
$form->addPassword('passwordVerify', 'Password again:')
->setRequired('Fill your password again to check for typo')
->addRule(Form::EQUAL, 'Password missmatch', $form['password']);
$form->addSubmit('send', 'Register');
$form->setDefaults([
'name' => 'John Doe',
'age' => 33,
]);
if ($form->isSubmitted() && $form->isValid()) {
echo 'Form was submitted and passed validation';
$values = $form->getValues();
dump($values);
}
echo $form;
?>
<style>
.required label { color: maroon }
</style>
<script src="netteForms.js"></script>