PluginProbe
Packeta / 2.1
Packeta v2.1
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
← All changes | deps/nette/forms/src/Forms/Form.php +10 -9 1.6.12.1 View file →
@@ -48,11 +48,11 @@
48 48 /** @var bool */
49 49 protected $crossOrigin = \false;
50 50 /** @var \Packetery\Nette\Http\IRequest */
51 51 private static $defaultHttpRequest;
52 - /** @var mixed or null meaning: not detected yet */
52 + /** @var SubmitterControl|bool */
53 53 private $submittedBy;
54 - /** @var array */
54 + /** @var array|null */
55 55 private $httpData;
56 56 /** @var Html element <form> */
57 57 private $element;
58 58 /** @var FormRenderer */
@@ -159,10 +159,11 @@
159 159 return $control;
160 160 }
161 161 /**
162 162 * Adds fieldset group to the form.
163 + * @param string|object $caption
163 164 */
164 - public function addGroup(string $caption = null, bool $setAsCurrent = \true) : ControlGroup
165 + public function addGroup($caption = null, bool $setAsCurrent = \true) : ControlGroup
165 166 {
166 167 $group = new ControlGroup();
167 168 $group->setOption('label', $caption);
168 169 $group->setOption('visual', \true);
@@ -236,9 +237,9 @@
236 237 * @return SubmitterControl|bool submittor control
237 238 */
238 239 public function isSubmitted()
239 240 {
240 - if ($this->submittedBy === null) {
241 + if ($this->httpData === null) {
241 242 $this->getHttpData();
242 243 }
243 244 return $this->submittedBy;
244 245 }
@@ -287,9 +288,11 @@
287 288 return;
288 289 } elseif (!$this->getErrors()) {
289 290 $this->validate();
290 291 }
292 + $handled = \count($this->onSuccess ?? []) || \count($this->onSubmit ?? []);
291 293 if ($this->submittedBy instanceof Controls\SubmitButton) {
294 + $handled = $handled || \count($this->submittedBy->onClick ?? []);
292 295 if ($this->isValid()) {
293 296 $this->invokeHandlers($this->submittedBy->onClick, $this->submittedBy);
294 297 } else {
295 298 Arrays::invoke($this->submittedBy->onInvalidClick, $this->submittedBy);
@@ -301,8 +304,11 @@
301 304 if (!$this->isValid()) {
302 305 Arrays::invoke($this->onError, $this);
303 306 }
304 307 Arrays::invoke($this->onSubmit, $this);
308 + if (!$handled) {
309 + \trigger_error("Form was submitted but there are no associated handlers (form '{$this->getName()}').", \E_USER_WARNING);
310 + }
305 311 }
306 312 private function invokeHandlers(iterable $handlers, $button = null) : void
307 313 {
308 314 foreach ($handlers as $handler) {
@@ -513,13 +519,8 @@
513 519 throw new \Packetery\Nette\InvalidStateException('Create a form or call \\Packetery\\Nette\\Forms\\Form::initialize() before the headers are sent to initialize CSRF protection.' . ($file ? " (output started at {$file}:{$line})" : '') . '. ');
514 520 }
515 521 \Packetery\Nette\Http\Helpers::initCookie(self::$defaultHttpRequest, new \Packetery\Nette\Http\Response());
516 522 }
517 - }
518 - /** @internal */
519 - public function setHttpRequest(\Packetery\Nette\Http\IRequest $request)
520 - {
521 - $this->httpRequest = $request;
522 523 }
523 524 private function getHttpRequest() : \Packetery\Nette\Http\IRequest
524 525 {
525 526 if (!$this->httpRequest) {