/** * Factory method for subcomponent form instance. * This factory is called internally by Nette in the component model. * * @return Form */ protected function createComponentForm() { $form = $this->formFactory->create(); $form->addText('email', 'Email')->setRequired('%label is required')->addRule($form::EMAIL); $form->addPassword('password', 'Password')->setRequired('%label is required'); $form->addPassword('confirm', 'Confirm')->setRequired('%label is required')->addRule(Form::EQUAL, 'New passwords must match', $form['password']); $form->addSubmit('send'); $form->onSuccess[] = [$this, 'formSucceeded']; $form->onValidate[] = function (Form $form, $values) { if ($this->userRepository->countBy(['email' => $values->email]) > 0) { $form->addError('Account with this email already exists'); } }; return $form; }