how to use Nette\Forms\Form into component
- alnux
- Member | 139
hi, im trying to use form into component but it tell me that i have to initialize, im using the last version of nette framework
i have this code by example
namespace Alnux\Nette;
use Exception;
use Nette\Application\UI\Control;
use Nette\Database\Table\Selection;
use Nette\Http\SessionSection;
use Nette\Forms\Form;
class MiniDataGrid extends Control {
public function loadState(array $params): void {
}
public function render(): void {
$form = $this->getComponent('contactForm');
$this->template->hola = 'hola';
$this->template->render(__DIR__ . '/Templates/hola.latte');
}
protected function createComponentContactForm(): Form
{
$form = new Form;
$form->addText('name', 'Name:')
->setRequired('Enter your name');
$form->addEmail('email', 'E-mail:')
->setRequired('Enter your e-mail');
$form->addTextarea('message', 'Message:')
->setRequired('Enter message');
$form->addSubmit('send', 'Send');
$form->onSuccess[] = [$this, 'contactFormSucceeded'];
return $form;
}
public function contactFormSucceeded(Form $form, $data): void
{
// sending an email
}
}
but the it show me an exception
Create a form or call Nette\Forms\Form::initialize() before the headers
are sent to initialize CSRF protection. (output started at
/Volumes/ALLEN-FILES/allenap/Documents/WEB3.0/DOMINIOS/GPS.ALNUXSOFT.COM/www/nette/temp/cache/latte/Common-Templates-@adminpanel.latte--de56674d5e.php:103).
targeting the $form->addText(‘name’,
‘Name:’) line.
Could someone help me how to use forms into components and how to render??
really really thanks
Last edited by alnux (2023-09-24 01:25)