Skip to content

Commit 3cb834e

Browse files
committed
Form: standalone HTTP processing split into new StandaloneForm (BC break)
Form is now a detached base: it builds, validates and renders, but has no access to submitted data (isAnchored() returns false, submission API throws InvalidStateException pointing to StandaloneForm). StandaloneForm extends Form and carries the standalone mechanics moved from Form: $httpRequest, static initialize(), receiveHttpData() with method/Sec-Fetch/tracker checks, the hidden '_form_' tracker and the TrackerId constant. Form::initialize() is removed. The base receiveHttpData() throws, making the isAnchored()/ receiveHttpData() pair contract loud in both directions. Descendants providing their own source of submitted data must override both (Nette\Application\UI\Form already does, it needs no change). Internal neutralizing anonymous classes in Repeater::createTemplate() and Blueprint::generateLatte() are simplified to plain `new Form`.
1 parent 0e8f641 commit 3cb834e

68 files changed

Lines changed: 1280 additions & 1121 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CLAUDE.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ npm run lint:fix
6363
### Core PHP Structure
6464

6565
**Class Hierarchy:**
66-
- `Form` (extends `Container`) - Main entry point for form creation
66+
- `Form` (extends `Container`) - Detached form: builds, validates and renders, but has no access to submitted data (`isAnchored()` returns `false`; submission API throws)
67+
- `StandaloneForm` (extends `Form`) - Detects submission and processes its own HTTP request (`$httpRequest`, static `initialize()`, `receiveHttpData()`, hidden `_form_` tracker); use outside Nette Application
68+
- `Nette\Application\UI\Form` (in nette/application, extends `Form`) - Anchored via presenter signals
6769
- `Container` - Holds controls and nested containers
6870
- `Control` (interface) - Contract for all form controls
6971
- `BaseControl` (abstract) - Base implementation for controls
7072

73+
Subclasses providing their own source of submitted data must override `receiveHttpData()` together with `isAnchored()` (or extend `StandaloneForm`).
74+
7175
**Form Controls** (in `src/Forms/Controls/`):
7276
- Abstract bases: `BaseControl`, `TextBase`, `ChoiceControl`, `MultiChoiceControl`
7377
- Text inputs: `TextInput` (also email/password/number via `addEmail()`, `addPassword()`, `addInteger()`, etc.), `TextArea`
@@ -169,6 +173,13 @@ testException('description', function () {
169173
- `addSubmit()` gained an `$onSubmit` parameter
170174
- Removed deprecated functionality and deprecated some magic properties (BC break)
171175

176+
### Breaking Changes (v4.0)
177+
178+
- Submitted data are accessed layer by layer via `getSubmittedData()` & `getSubmittedValue()`; `getHttpData()` is deprecated
179+
- Standalone HTTP processing split off `Form` into new `StandaloneForm`: `new Form` no longer autodetects submission (submission API throws `InvalidStateException`), `Form::initialize()` removed (use `StandaloneForm::initialize()`), `TrackerId`/`$httpRequest` moved to `StandaloneForm`, `Form::isAnchored()` returns `false`
180+
181+
(Design rationale for both changes is recorded as ADRs 0001 and 0002 in the machine-local private `docs/decisions/`, which exists only in the primary working clone.)
182+
172183
### New Latte features (v3.3)
173184

174185
- `{form scope name}` as an alternative to `{formContext name}`
@@ -527,8 +538,8 @@ $form->addPassword('passwordVerify')
527538

528539
**Sec-Fetch/Origin header protection** (enabled by default):
529540
```php
530-
// Create form before sending output to set _nss cookie
531-
$form = new Form;
541+
// standalone usage; POST submissions require the Sec-Fetch-Site: same-origin header
542+
$form = new StandaloneForm;
532543
```
533544

534545
**Cross-origin forms** (use carefully):

examples/basic-example.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
die('Install packages using `composer install`');
1010
}
1111

12-
use Nette\Forms\Form;
12+
use Nette\Forms\StandaloneForm;
1313
use Nette\Utils\Html;
1414
use Tracy\Debugger;
1515
use Tracy\Dumper;
1616

1717
Debugger::enable();
1818

1919

20-
$form = new Form;
20+
$form = new StandaloneForm;
2121

2222
// group Personal data
2323
$form->addGroup('Personal data')

examples/bootstrap4-rendering.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111

1212
use Nette\Forms\Form;
13+
use Nette\Forms\StandaloneForm;
1314
use Tracy\Debugger;
1415
use Tracy\Dumper;
1516

@@ -53,7 +54,7 @@ function makeBootstrap4(Form $form): void
5354
}
5455

5556

56-
$form = new Form;
57+
$form = new StandaloneForm;
5758
$form->onRender[] = 'makeBootstrap4';
5859

5960
$form->addGroup('Personal data');

examples/bootstrap5-rendering.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111

1212
use Nette\Forms\Form;
13+
use Nette\Forms\StandaloneForm;
1314
use Tracy\Debugger;
1415
use Tracy\Dumper;
1516

@@ -53,7 +54,7 @@ function makeBootstrap5(Form $form): void
5354
}
5455

5556

56-
$form = new Form;
57+
$form = new StandaloneForm;
5758
$form->onRender[] = 'makeBootstrap5';
5859

5960
$form->addGroup('Personal data');

examples/containers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
die('Install packages using `composer install`');
1010
}
1111

12-
use Nette\Forms\Form;
12+
use Nette\Forms\StandaloneForm;
1313
use Tracy\Debugger;
1414
use Tracy\Dumper;
1515

1616
Debugger::enable();
1717

1818

19-
$form = new Form;
19+
$form = new StandaloneForm;
2020

2121
// group First person
2222
$form->addGroup('First person');

examples/custom-control.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
}
1111

1212
use Nette\Forms\Form;
13+
use Nette\Forms\StandaloneForm;
1314
use Nette\Forms\Helpers;
1415
use Nette\Utils\Html;
1516

@@ -106,7 +107,7 @@ public static function validateDate(Nette\Forms\Control $control): bool
106107

107108
Tracy\Debugger::enable();
108109

109-
$form = new Form;
110+
$form = new StandaloneForm;
110111

111112
$form['date'] = new DateInput('Date:');
112113
$form['date']->setDefaultValue(new DateTime);

examples/custom-rendering.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
die('Install packages using `composer install`');
1010
}
1111

12-
use Nette\Forms\Form;
12+
use Nette\Forms\StandaloneForm;
1313
use Nette\Utils\Html;
1414
use Tracy\Debugger;
1515
use Tracy\Dumper;
1616

1717
Debugger::enable();
1818

1919

20-
$form = new Form;
20+
$form = new StandaloneForm;
2121
// setup custom rendering
2222
$renderer = $form->getRenderer();
2323
$renderer->wrappers['form']['container'] = Html::el('div')->id('form');

examples/custom-validator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
die('Install packages using `composer install`');
1010
}
1111

12-
use Nette\Forms\Form;
12+
use Nette\Forms\StandaloneForm;
1313
use Tracy\Debugger;
1414
use Tracy\Dumper;
1515

@@ -26,7 +26,7 @@ public static function divisibilityValidator($item, $arg): bool
2626
}
2727

2828

29-
$form = new Form;
29+
$form = new StandaloneForm;
3030

3131
$form->addText('num1', 'Multiple of 8:')
3232
->setDefaultValue(5)

examples/html5.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
die('Install packages using `composer install`');
1010
}
1111

12-
use Nette\Forms\Form;
12+
use Nette\Forms\StandaloneForm;
1313
use Tracy\Debugger;
1414
use Tracy\Dumper;
1515

1616
Debugger::enable();
1717

1818

19-
$form = new Form;
19+
$form = new StandaloneForm;
2020

2121
$form->addGroup();
2222

examples/latte.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
die('Install packages using `composer install`');
1010
}
1111

12-
use Nette\Forms\Form;
12+
use Nette\Forms\StandaloneForm;
1313
use Tracy\Debugger;
1414
use Tracy\Dumper;
1515

1616
Debugger::enable();
1717

1818

19-
$form = new Form;
19+
$form = new StandaloneForm;
2020
$form->addText('name', 'Your name')
2121
->setRequired('Enter your name')
2222
->setOption('description', 'Name and surname');

0 commit comments

Comments
 (0)