• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / application / 27919019709

21 Jun 2026 10:08PM UTC coverage: 84.111% (+0.05%) from 84.059%
27919019709

push

github

dg
phpstan fix

2038 of 2423 relevant lines covered (84.11%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

37.21
/src/Application/UI/Form.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Nette\Application\UI;
9

10
use Nette;
11

12

13
/**
14
 * Web form adapted for Presenter.
15
 */
16
class Form extends Nette\Forms\Form implements SignalReceiver
17
{
18
        /** @var array<callable(static): void>  Occurs when form is attached to presenter */
19
        public array $onAnchor = [];
20

21

22
        public function __construct(?Nette\ComponentModel\IContainer $parent = null, ?string $name = null)
1✔
23
        {
24
                parent::__construct();
1✔
25
                $parent?->addComponent($this, $name);
1✔
26
        }
1✔
27

28

29
        protected function validateParent(Nette\ComponentModel\IContainer $parent): void
1✔
30
        {
31
                parent::validateParent($parent);
1✔
32

33
                $this->monitor(Presenter::class, function (Presenter $presenter): void {
1✔
34
                        if (!isset($this->getElementPrototype()->id)) {
1✔
35
                                $this->getElementPrototype()->id = 'frm-' . $this->lookupPath(Presenter::class);
1✔
36
                        }
37

38
                        if (!$this->getAction()) {
1✔
39
                                $this->setAction(new Link($presenter, 'this'));
1✔
40
                        }
41

42
                        $controls = $this->getControls();
1✔
43
                        if (iterator_count($controls) && $this->isSubmitted()) {
1✔
44
                                foreach ($controls as $control) {
45
                                        if (!$control->isDisabled()) {
46
                                                $control->loadHttpData();
47
                                        }
48
                                }
49
                        }
50

51
                        Nette\Utils\Arrays::invoke($this->onAnchor, $this);
1✔
52
                });
1✔
53
        }
1✔
54

55

56
        /**
57
         * Returns the presenter where this component belongs to. Throws if not attached.
58
         * @return ($throw is true ? Presenter : ?Presenter)
59
         */
60
        final public function getPresenter(bool $throw = true): ?Presenter
61
        {
62
                return $this->lookup(Presenter::class, $throw);
×
63
        }
64

65

66
        /**
67
         * Returns the presenter where this component belongs to, or null if not attached.
68
         * @deprecated
69
         */
70
        final public function getPresenterIfExists(): ?Presenter
71
        {
72
                return $this->lookup(Presenter::class, throw: false);
×
73
        }
74

75

76
        /** @deprecated */
77
        public function hasPresenter(): bool
78
        {
79
                return (bool) $this->lookup(Presenter::class, throw: false);
×
80
        }
81

82

83
        /**
84
         * Tells if the form is anchored.
85
         */
86
        public function isAnchored(): bool
87
        {
88
                return (bool) $this->getPresenter(throw: false);
×
89
        }
90

91

92
        /** @deprecated  use allowCrossOrigin() */
93
        public function disableSameSiteProtection(): void
94
        {
95
                $this->allowCrossOrigin();
×
96
        }
97

98

99
        /**
100
         * Internal: returns submitted HTTP data or null when form was not submitted.
101
         */
102
        protected function receiveHttpData(): ?array
103
        {
104
                $presenter = $this->getPresenter();
×
105
                if (!$presenter->isSignalReceiver($this, 'submit')) {
×
106
                        return null;
×
107
                }
108

109
                $request = $presenter->getRequest();
×
110
                if ($request->isMethod('forward') || $request->isMethod('post') !== $this->isMethod('post')) {
×
111
                        return null;
×
112
                }
113

114
                return $this->isMethod('post')
×
115
                        ? Nette\Utils\Arrays::mergeTree($request->getPost(), $request->getFiles())
×
116
                        : $request->getParameters();
×
117
        }
118

119

120
        protected function beforeRender(): void
121
        {
122
                parent::beforeRender();
×
123
                $key = ($this->isMethod('post') ? '_' : '') . Presenter::SignalKey;
×
124
                if (!isset($this[$key]) && $this->getAction() !== '') {
×
125
                        $do = $this->lookupPath(Presenter::class) . self::NameSeparator . 'submit';
×
126
                        $this[$key] = (new Nette\Forms\Controls\HiddenField($do))->setOmitted();
×
127
                }
128
        }
129

130

131
        /********************* interface SignalReceiver ****************d*g**/
132

133

134
        /**
135
         * This method is called by presenter.
136
         */
137
        public function signalReceived(string $signal): void
138
        {
139
                $presenter = $this->getPresenter();
×
140
                if ($signal !== 'submit') {
×
141
                        $class = static::class;
×
142
                        throw new BadSignalException("Missing handler for signal '$signal' in $class.");
×
143

144
                } elseif (!$this->crossOrigin && !$presenter->getHttpRequest()->isSameSite()) {
×
145
                        $presenter->detectedCsrf();
×
146

147
                } elseif (!$presenter->getRequest()->hasFlag(Nette\Application\Request::RESTORED)) {
×
148
                        $this->fireEvents();
×
149
                }
150
        }
151
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc