upgrade to forms 3.1.8: how to manage headers to getHttpData
- mikeb
- Member | 33
Hi
Im upgrading from standalone forms 2.4 to 3.1.8 (as am moving to php8.2.4).
Some simple forms work fine. But on one form I make the form then get the
getHttpData for various tests of posted data:
$form = new Nette\Forms\Form;
$reg_code_posted = ($form->getHttpData($form::DATA_TEXT, 'reg_code')) ? true : false;
But now with 3.1.8 I get:
Fatal error: Uncaught Nette\InvalidStateException: Create a form or call Nette\Forms\Form::initialize() before the headers are sent to initialize CSRF protection.
Can someone advise me how to manage this? I have tried to ->addProtection()
or starting session but without success.
Thanks!
- Marek Bartoš
- Nette Blogger | 1275
You can call \Tracy\OutputDebugger::enable();
from tracy just before creating form
instance to find out, in which place is page content first echoed and therefore
when are the headers sent. You should create Form before the headers
are send.
Or just call \Nette\Forms\Form::initialize();
e.g. right after
including vendor/autoload.php
to work around that.