PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
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 / bootstrap2-rendering.php

bootstrap2-rendering.php in Packeta 2.0.9, at deps/nette/forms/examples/bootstrap2-rendering.php

74 lines 2.6 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 & Bootstap v2 rendering example.
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 function makeBootstrap2(Form $form) : void
17 {
18 $renderer = $form->getRenderer();
19 $renderer->wrappers['controls']['container'] = null;
20 $renderer->wrappers['pair']['container'] = 'div class=control-group';
21 $renderer->wrappers['pair']['.error'] = 'error';
22 $renderer->wrappers['control']['container'] = 'div class=controls';
23 $renderer->wrappers['label']['container'] = 'div class=control-label';
24 $renderer->wrappers['control']['description'] = 'span class=help-inline';
25 $renderer->wrappers['control']['errorcontainer'] = 'span class=help-inline';
26 $form->getElementPrototype()->class('form-horizontal');
27 foreach ($form->getControls() as $control) {
28 $type = $control->getOption('type');
29 if ($type === 'button') {
30 $control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn');
31 $usedPrimary = \true;
32 } elseif (\in_array($type, ['checkbox', 'radio'], \true)) {
33 $control->getSeparatorPrototype()->setName('div')->addClass($type);
34 }
35 }
36 }
37 $form = new Form();
38 $form->onRender[] = 'makeBootstrap2';
39 $form->addGroup('Personal data');
40 $form->addText('name', 'Your name')->setRequired('Enter your name');
41 $form->addRadioList('gender', 'Your gender', ['male', 'female']);
42 $form->addCheckboxList('colors', 'Favorite colors', ['red', 'green', 'blue']);
43 $form->addSelect('country', 'Country', ['Buranda', 'Qumran', 'Saint Georges Island']);
44 $form->addCheckbox('send', 'Ship to address');
45 $form->addGroup('Your account');
46 $form->addPassword('password', 'Choose password');
47 $form->addUpload('avatar', 'Picture');
48 $form->addTextArea('note', 'Comment');
49 $form->addGroup();
50 $form->addSubmit('submit', 'Send');
51 $form->addSubmit('cancel', 'Cancel');
52 if ($form->isSuccess()) {
53 echo '<h2>Form was submitted and successfully validated</h2>';
54 Dumper::dump($form->getValues());
55 exit;
56 }
57 ?>
58 <!DOCTYPE html>
59 <meta charset="utf-8">
60 <title>Nette Forms & Bootstrap v2 rendering example</title>
61
62 <link rel="stylesheet" media="screen" href="https://netdna.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css" />
63
64 <div class="container">
65 <div class="page-header">
66 <h1>Nette Forms & Bootstrap v2 rendering example</h1>
67 </div>
68
69 <?php
70 $form->render();
71 ?>
72 </div>
73 <?php
74