PluginProbe
Packeta / trunk
Packeta vtrunk
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / deps / nette / forms / examples / manual-rendering.php

manual-rendering.php in Packeta trunk, at deps/nette/forms/examples/manual-rendering.php

120 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Nette Forms manual form rendering.
5 */
6 declare (strict_types=1);
7 namespace Packetery;
8
9 if (@(!(include __DIR__ . '/../vendor/autoload.php'))) {
10 die('Install packages using `composer install`');
11 }
12 use Packetery\Nette\Forms\Form;
13 use Packetery\Tracy\Debugger;
14 use Packetery\Tracy\Dumper;
15 Debugger::enable();
16 $form = new Form();
17 $form->addText('name')->setRequired('Enter your name');
18 $form->addText('age')->setRequired('Enter your age');
19 $form->addRadioList('gender', null, ['m' => 'male', 'f' => 'female']);
20 $form->addEmail('email');
21 $form->addSubmit('submit');
22 if ($form->isSuccess()) {
23 echo '<h2>Form was submitted and successfully validated</h2>';
24 Dumper::dump($form->getValues());
25 exit;
26 }
27 ?>
28 <!DOCTYPE html>
29 <html>
30 <head>
31 <meta charset="utf-8">
32 <title>Nette Forms manual form rendering</title>
33 <link rel="stylesheet" media="screen" href="assets/style.css" />
34 <script src="https://nette.github.io/resources/js/3/netteForms.js"></script>
35 </head>
36
37 <body>
38 <h1>Nette Forms manual form rendering</h1>
39
40 <?php
41 $form->render('begin');
42 ?>
43
44 <?php
45 if ($form->errors) {
46 ?>
47 <ul class="error">
48 <?php
49 foreach ($form->errors as $error) {
50 ?>
51 <li><?php
52 echo \htmlspecialchars($error);
53 ?></li>
54 <?php
55 }
56 ?>
57 </ul>
58 <?php
59 }
60 ?>
61
62 <fieldset>
63 <legend>Personal data</legend>
64 <table>
65 <tr class="required">
66 <th><?php
67 echo $form['name']->getLabel('Your name:');
68 ?></th>
69 <td><?php
70 echo $form['name']->control->cols(35);
71 ?> <?php
72 echo $form['name']->error;
73 ?></td>
74 </tr>
75 <tr class="required">
76 <th><?php
77 echo $form['age']->getLabel('Your age:');
78 ?></th>
79 <td><?php
80 echo $form['age']->control->cols(5);
81 ?> <?php
82 echo $form['age']->error;
83 ?></td>
84 </tr>
85 <tr>
86 <th><?php
87 echo $form['gender']->getLabel('Your gender:');
88 ?></th>
89 <td><?php
90 echo $form['gender']->control;
91 ?> <?php
92 echo $form['gender']->error;
93 ?></td>
94 </tr>
95 <tr>
96 <th><?php
97 echo $form['email']->getLabel('Email:');
98 ?></th>
99 <td><?php
100 echo $form['email']->control->cols(35);
101 ?> <?php
102 echo $form['email']->error;
103 ?></td>
104 </tr>
105 </table>
106 </fieldset>
107
108 <div>
109 <?php
110 echo $form['submit']->getControl('Send');
111 ?>
112 </div>
113
114 <?php
115 $form->render('end');
116 ?>
117 </body>
118 </html>
119 <?php
120