48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace App\UI\Form;
|
||
|
|
||
|
use Nette\Application\UI\Form;
|
||
|
use Nette\Forms\Form as NetteForm;
|
||
|
use Nette\Localization\Translator;
|
||
|
|
||
|
class SurveyFormFactory
|
||
|
{
|
||
|
public function __construct(
|
||
|
protected readonly Translator $translator,
|
||
|
) {
|
||
|
}
|
||
|
public function create(): Form
|
||
|
{
|
||
|
$form = new Form();
|
||
|
|
||
|
$form->setTranslator($this->translator);
|
||
|
|
||
|
$form->addText('name', 'survey.name')
|
||
|
->setRequired('survey.name_required')
|
||
|
->addRule(NetteForm::MaxLength, $this->translator->translate('survey.name_is_too_long'), 255);
|
||
|
|
||
|
|
||
|
$form->addTextArea('comments', 'survey.comments');
|
||
|
|
||
|
$form->addCheckbox('agreement', 'survey.agreement')
|
||
|
->setRequired('survey.agreement_required');
|
||
|
|
||
|
$form->addMultiSelect('interests', 'survey.interests', [
|
||
|
'sport' => 'survey.interests.sport',
|
||
|
'music' => 'survey.interests.music',
|
||
|
'travel' => 'survey.interests.travel',
|
||
|
])->setRequired('survey.interests_required')
|
||
|
->addRule(NetteForm::MaxLength, $this->translator->translate('survey.interest_is_too_long'), 255);
|
||
|
|
||
|
|
||
|
$form->addSubmit('send', 'survey.send');
|
||
|
|
||
|
$form->addProtection('survey.protection');
|
||
|
|
||
|
return $form;
|
||
|
}
|
||
|
}
|